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 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值