Skip to content

Java convert String to double example

This example shows how to convert string to double in Java using the parseDouble method of the Double wrapper class including the NumberFormatException.

How to convert String to double in Java?

To convert string to double, use the parseDouble method of the Double wrapper class.

This method returns double primitive value by parsing the input string value.

Output

Important Note:

If the input string value cannot be parsed to a double value, the parseDouble method throws a NumberFormatException exception.

Also, if the string is null, the parseDouble method throws a NullPointerException exception.

Output

Here are some of the example string values and their possible outputs.

Please note that the “+” (plus sign) or “-” (Minus sign) is allowed as a first character of the string to denote positive and negative value numbers respectively.

This example is a part of the Java Basic Examples and Java Type conversion Tutorial.

Please let me know your views in the comments section below.

About the author

Leave a Reply

Your email address will not be published.