Double類parseDouble()方法 (Double class parseDouble() method)
parseDouble() method is available in java.lang package.
parseDouble()方法在java.lang包中可用。
parseDouble() method is used to return the double value corresponding to the given String or in other words we can say this method is used to convert a string value to double value.
parseDouble()方法用于返回對應于給定String的double值,換句話說,我們可以說此方法用于將字符串值轉換為double值。
parseDouble() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
parseDouble()方法是一個靜態方法,也可以使用類名進行訪問,如果我們嘗試使用類對象訪問該方法,那么我們也不會收到錯誤。
parseDouble() method may throw a NumberFormatException at the time of conversion from string double,
從字符串double轉換時, parseDouble()方法可能會引發NumberFormatException,
NumberFormatException: In this exception, when the string argument does not have parsable double.
NumberFormatException:在此異常中,當string參數沒有可分析的double時。
Syntax:
句法:
public static double parseDouble(String str);
Parameter(s):
參數:
String str – represents the string value to be parsed.
字符串str –表示要解析的字符串值。
Return value:
返回值:
The return type of this method is double, it returns the corresponding double value.
此方法的返回類型為double ,它返回相應的double值。
Example:
例:
// Java program to demonstrate the example
// of parseDouble(String str) method of Double class
public class ParseDoubleOfDoubleClass {
public static void main(String[] args) {
// Variables initialization
String str1 = "100";
String str2 = "6.7";
// Object initialization
Double d1 = new Double(str2);
// It convert string into double by calling parseDouble() method
// and store the result in another variable of double type
double result = d1.parseDouble(str1);
// Display result
System.out.println("d1.parseDouble(str1): " + result);
}
}
Output
輸出量
d1.parseDouble(str1): 100.0
翻譯自: https://www.includehelp.com/java/double-class-parsedouble-method-with-example.aspx