Convert double value to String in Java

static String valueOf(double b) method of String class can be used to convert a double value to String in Java.

For eg. when we pass a double value '16.666666' to valueOf method, it returns a string value '16.666666'.


Example 1

class DtoSTest{

public static void main(String args[]){

double d=16.666666;

String doubtoSt=String.valueOf(d);

System.out.println(doubtoSt);

}

}

Output 1

16.666666


Example 2

class DtoSTest{

public static void main(String args[]){

double g=77.666666;

String doubtoSt=String.valueOf(g);

System.out.println(doubtoSt);

}

}

Output 2

77.666666