Convert String to Double in Java
Given a String, the task is to convert it into Double in Java.
Examples:
Input: String = "20.156" Output: 20.156 Input: String = "456.21" Output: 456.21
We can use various methods to perform the task :
- Using Double.parseDouble()
Syntax:
double str1 = Double.parseDouble(str);
// Java program to convert String to Double// using parseDouble()publicclassGFG {// main methodpublicstaticvoidmain(String args[]){// create a StringString str ="2033.12244";// convert into Doubledoublestr1 = Double.parseDouble(str);// print String as DoubleSystem.out.println(str1);}}chevron_rightfilter_noneOutput:2033.12244
- Using Double.valueOf()
Syntax:
double str1 = Double.valueOf(str);
Examples:
// Java program to convert String to Double// using parseDouble()publicclassGFG {// main methodpublicstaticvoidmain(String args[]){// create a StringString str ="2033.12244";// convert into Doubledoublestr1 = Double.valueOf(str);// print String as DoubleSystem.out.println(str1);}}chevron_rightfilter_noneOutput:2033.12244
- Using constructor of Double class
Syntax:
Double str1 = new Double(str);
Examples:
// Java program to convert String to Double// using parseDouble()publicclassGFG {// main methodpublicstaticvoidmain(String args[]){// create a StringString str ="2033.12244";// convert into DoubleDouble str1 =newDouble(str);// print String as DoubleSystem.out.println(str1);}}chevron_rightfilter_noneOutput:2033.12244
- Convert Double to Integer in Java
- Convert a List of String to a comma separated String in Java
- Convert an ArrayList of String to a String array in Java
- Convert a Set of String to a comma separated String in Java
- Convert Set of String to Array of String in Java
- Java Guava | Doubles.indexOf(double[] array, double target) method with Examples
- Java Guava | Doubles.indexOf(double[] array, double[] target) method with Examples
- How to convert a String to an Int in Java?
- Convert String to Date in Java
- How to convert an Array to String in Java?
- Program to convert String to IntStream in Java
- Program to convert IntStream to String in Java
- Program to Convert Set of Integer to Set of String in Java
- Convert a String to Character array in Java
- Program to convert set of String to set of Integer in Java
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



