Parse a string as a double-precision floating-point number.
The Double.parseDouble() method returns a new double initialized to the value represented by the specified string. It can parse decimal literals, hexadecimal floating-point literals, and the special strings "NaN", "Infinity", and "-Infinity".
The string must represent a valid floating-point number or a NumberFormatException is thrown. Leading and trailing whitespace is handled by trim() before parsing. Scientific notation (e.g., "3.14e2") is supported.
This method is commonly used for parsing numeric input from files, user interfaces, network data, and configuration files. For locale-sensitive number parsing (e.g., using comma as decimal separator), use NumberFormat.parse() instead.
| Name | Description | Optional |
|---|---|---|
s |
The String to be parsed. | No |
Double.parseDouble("3.14"); // 3.14
Double.parseDouble("-0.5"); // -0.5
Double.parseDouble("3.14e2"); // 314.0
Double.parseDouble("NaN"); // NaN