Double.parseDouble() in Java

Double.parseDouble(): This method is available in java.lang.Double class of Java.

Syntax:

double java.lang.Double.parseDouble(String s) throws NumberFormatException

This method takes one argument of type String as its parameter. This method returns a new double initialized to the value represented by the specified String.

Parameters: One parameter is required for this method.

s: the string to be parsed.

Returns: the double value represented by the string argument.

Throws: NullPointerException - if the string is nullNumberFormatException - if the string does not contain a parsable double.

For Example:

String s = "1818.99"

Double.parseDouble(s) = > It returns 1818.99

Approach

Java

public class DoubleparseDouble {
    public static void main(String[] args) {

        String s = "1818.99";
        System.out.println(Double.parseDouble(s));

    }
}

Output:

1818.99

No comments:

Post a Comment