Java Double类parseDouble()方法的示例
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 classpublic class ParseDoubleOfDoubleClass {public static void main(String[] args) {// Variables initializationString str1 = "100";String str2 = "6.7";// Object initializationDouble d1 = new Double(str2);// It convert string into double by calling parseDouble() method// and store the result in another variable of double typedouble result = d1.parseDouble(str1);// Display resultSystem.out.println("d1.parseDouble(str1): " + result);} }Output
輸出量
d1.parseDouble(str1): 100.0翻譯自: https://www.includehelp.com/java/double-class-parsedouble-method-with-example.aspx
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Java Double类parseDouble()方法的示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java FileInputStream
- 下一篇: 亲爹后爸剧情介绍