Double to String example in Java

Lets look at different ways through which we can convert Double value to String in Java. Note that double is a primitive data type whereas Double is an Object. However java supports autoboxing, so they both can be used interchangeably in most of the cases.

1. Using + operator

This is the easiest way to convert double to string in java.

2. Double.toString()

We can use Double class toString method to get the string representation of double in decimal points. Below code snippet shows you how to use it to convert double to string in java.

3. String.valueOf()

4. new Double(double l)

Double constructor with double argument has been deprecated in Java 9, but you should know it.

5. String.format()

We can use Java String format method to convert double to String in our programs.

6. DecimalFormat

We can use DecimalFormat class to convert double to String. We can also get string representation with specified decimal places and rounding of half-up.

7. StringBuilder and StringBuffer

We can use StringBuilder and StringBuffer append function to convert double to string.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Notify of