Java Double - parseDouble() Method
The java.lang.Double.parseDouble() method returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.
Syntax
public static double parseDouble(String s) throws NumberFormatException
Parameters
s |
Specify the string to be parsed. |
Return Value
Returns the double value represented by the string argument.
Exception
- Throws NullPointerException, if the string is null.
- Throws NumberFormatException, if the string does not contain a parsable double.
Example:
In the example below, the java.lang.Double.parseDouble() method is used to parse the string argument as a double value.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating a string holding double value String x = "25.2"; //creating double value double y = Double.parseDouble(x); //printing the string System.out.println("The string is: " + x); //printing the double value System.out.println("The double value is: " + y); } }
The output of the above code will be:
The string is: 25.2 The double value is: 25.2
❮ Java.lang - Double