Java double to String

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Java Convert double to String

We can convert double to String in java using String.valueOf() and Double.toString() methods.


It is generally used if we have to display double value in textfield for GUI application because everything is displayed as a string in form.

1) String.valueOf()

The String.valueOf() is an overloaded method. It can be used to convert double to String. The valueOf() is the static method of String class. The signature of valueOf() method for the double conversion is given below:

  1. public static String valueOf(double d)  

Java double to String Example: String.valueOf()

Let's see the simple code to convert double to String in java.

  1. double d=12.3;//floating literal is double by default  

  2. String s=String.valueOf(d);  


  1. public class DoubleToStringExample1{  
  2. public static void main(String args[]){  
  3. double d=12.3;  
  4. String s=String.valueOf(d);  
  5. System.out.println(s);  
  6. }}  



2) Double.toString()

The Double.toString() method also converts float to String. The toString() is the static method of Double class. The signature of toString() method is given below:

  1. public static String toString(double d)  

Java double to String Example: Double.toString()

Let's see the simple code to convert double to String in java using Double.toString() method.

  1. double d=89.7;  

  2. String s=Double.toString(d);


  1. public class DoubleToStringExample2{  
  2. public static void main(String args[]){  
  3. double d=89.7;  
  4. String s=Double.toString(d);  
  5. System.out.println(s);  
  6. }}