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()方法用于返回對(duì)應(yīng)于給定String的double值,換句話說(shuō),我們可以說(shuō)此方法用于將字符串值轉(zhuǎn)換為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()方法是一個(gè)靜態(tài)方法,也可以使用類名進(jìn)行訪問(wèn),如果我們嘗試使用類對(duì)象訪問(wèn)該方法,那么我們也不會(huì)收到錯(cuò)誤。
parseDouble() method may throw a NumberFormatException at the time of conversion from string double,
從字符串double轉(zhuǎn)換時(shí), parseDouble()方法可能會(huì)引發(fā)NumberFormatException,
NumberFormatException: In this exception, when the string argument does not have parsable double.
NumberFormatException:在此異常中,當(dāng)string參數(shù)沒(méi)有可分析的double時(shí)。
Syntax:
句法:
public static double parseDouble(String str);Parameter(s):
參數(shù):
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 ,它返回相應(yīng)的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
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的Java Double类parseDouble()方法的示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Java FileInputStream
- 下一篇: doublevalue_Java Dou