by Sai gowtham

How to Convert the String to a Double in Java

To convert a string to a double, we can use the Double.parseDouble() method in Java.

Here is an example that converts the string 12.44 to a double.

String s = "12.44";  // string
double price = Double.parseDouble(s);
System.out.println(price);

Output:

12.44

Similarly, you can also use the Double.valueof() method to convert it.

String s = "12.44";
double price = Double.valueOf(s);
System.out.println(price);

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course