Convert string value to double

static double parseDouble(String s)
Returns a double to the value represented by the String.
static Double valueOf(double d)
Returns a Double instance representing the double value.
static Double valueOf(String s)
Returns a Double object holding the double value represented by the argument string s.

public class Main {
  public static void main(String[] args) {
    
    System.out.println(Double.valueOf("1.234"));

  }
}

The output:


1.234

Double.valueOf can also be used to check if a string is a number.


public class Main {
  public static void main(String[] args) {
    
    System.out.println(Double.valueOf("1.abc"));

  }
}

The code above produces the following error message:


Exception in thread "main" java.lang.NumberFormatException: For input string: "1.abc"
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
    at java.lang.Double.valueOf(Double.java:475)
    at Main.main(Main.java:4)

You can use the Double.parseDouble in the same way
Home 
  Java Book 
    Essential Classes  

Double:
  1. Double class
  2. Constants in Double class
  3. Double class Constructor
  4. Return double value as byte, double, float, int, long, short
  5. Compare two double values
  6. Is a double value an infinite large value, or it is not a number.
  7. Convert string value to double
  8. Convert double value from string
  9. Get the hexadecimal string representation
  10. Bit oriented calculation for double type