Home »
Java Programs »
Java Conversion Programs
Conversion from String to Double in Java
Java conversion from String to Double: Here, we are going to learn how to convert a given string value to a double in Java?
Submitted by IncludeHelp, on July 16, 2019
Problem statement
Given a string value and we have to convert it into a double.
Java conversion from String to Double
To convert a String to Double, we can use the following methods of Double class (see the syntax given below...)
Syntax
Double Double.valueOf(String).doubleValue();
OR
Double Double.parseDouble(String);
Java program to convert a String to Double
//Java code to convert String to Double
public class Main {
public static void main(String args[]) {
String str = "12345.87878d";
//variable to store result
double result = 0;
//converting string to double
//method 1
result = Double.valueOf(str).doubleValue();
System.out.println("result (value of str as double) = " + result);
//method 2
result = Double.parseDouble(str);
System.out.println("result (value of str as double) = " + result);
}
}
Output
result (value of str as double) = 12345.87878
result (value of str as double) = 12345.87878
Java Conversion Programs »