We can convert Double to String in Java using the following methods:
- String.valueOf() method
- Double.toString() method
Convert Double to String in Java using the String.valueOf() method
There are multiple overloaded versions of the valueOf() method from the String class. We will use the one which accepts double.
Example
class Test { public static void main(String[] args) { String s1 = String.valueOf(123.5); String s2 = String.valueOf(8252.1); String s3 = String.valueOf(12.8); System.out.println(s1); System.out.println(s2); System.out.println(s3); } }
Output: 123.5 8252.1 12.8
Parse Double to String using the Double.toString() method
We can also use the static method toString() of the Double class. It returns a String representations of a provided double.
Example
class Test { public static void main(String[] args) { String s1 = Double.toString(123.5); String s2 = Double.toString(8252.1); String s3 = Double.toString(12.8); System.out.println(s1); System.out.println(s2); System.out.println(s3); } }
Output: 123.5 8252.1 12.8
That’s it!
Happy coding!