Home » Java Double parseDouble() Method with Examples

Java Double parseDouble() Method with Examples

by Online Tutorials Library

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

Test it Now

Output:

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

Example 2

Test it Now

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

Test it Now

Output:

Enter any string:[email protected]  Exception in thread "main" java.lang.NumberFormatException: For input string: "[email protected]"  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

Test it Now

Output:

Enter any string:[email protected]  An exception java.lang.NumberFormatException: For input string: "[email protected]" has occured.  Plz enter a valid double integer  

Next TopicJava Double

You may also like