在Java中从字符串转换为双精度
生活随笔
收集整理的這篇文章主要介紹了
在Java中从字符串转换为双精度
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Given a string value and we have to convert it into a double.
給定一個字符串值,我們必須將其轉換為雙精度型。
Java conversion from String to Double
Java從String轉換為Double
To convert a String to Double, we can use the following methods of Double class (see the syntax given below...)
要將String轉換為Double ,我們可以使用Double類的以下方法(請參見下面給出的語法...)
Syntax:
句法:
Double Double.valueOf(String).doubleValue(); OR Double Double.parseDouble(String);Java代碼將字符串轉換為Double (Java code to convert a String to Double)
//Java code to convert String to Double public class Main {public static void main(String args[]) {String str = "12345.87878d";//variable to store resultdouble result = 0;//converting string to double//method 1result = Double.valueOf(str).doubleValue();System.out.println("result (value of str as double) = " + result);//method 2result = Double.parseDouble(str);System.out.println("result (value of str as double) = " + result);} }Output
輸出量
result (value of str as double) = 12345.87878 result (value of str as double) = 12345.87878翻譯自: https://www.includehelp.com/java-programs/conversion-from-string-to-double-in-java.aspx
總結
以上是生活随笔為你收集整理的在Java中从字符串转换为双精度的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html 链接 id属性_HTML id
- 下一篇: stl取出字符串中的字符_在C ++ S