Java Double parseDouble() Method

The parseDouble method of Java Double class returns a new double value that is initialized to the value corresponding to defined String.

This method executes same as valueOf() method of Float class.

Syntax

Parameters

s- This is the string to be parsed.

Return value

The parseDouble() method returns the double value corresponding to the parameter passed.

Throws

The parseDouble() method throws:

1.NullPointerException- if the string passed is null.

2.NumberFormatException- if the string passed does not hold a parsable float.

Example 1

Output:

1. Sum =1000156.0
2. Sum =1156.0
3. Multiplication =156000.0
4. Division =6.410256410256411
5. Reminder =64.0

Example 2

Output:

Enter your age:09
Sorry! You are not eligible.Try again after 44.0 years
Your year of birth is = 2009.0

Example 3

Output:

Enter any string:Himanshu@123
Exception in thread "main" java.lang.NumberFormatException: For input string: "Himanshu@123"
	at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
	at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
	at java.lang.Double.parseDouble(Double.java:538)

Example 4

Output:

Enter any string:himanshu@123
An exception java.lang.NumberFormatException: For input string: "himanshu@123" has occured.
Plz enter a valid double integer