Java Convert Double to String

Last Updated : 29 Sept 2026

Double-digit integers in Java programming often need to be converted to strings. It is especially true for graphical user interface (GUI) applications, where strings are typically used to represent numerical amounts in a readable way. In order to provide data to users in a comprehensible manner, this conversion procedure is essential. In this section, we will discuss widely used methods for converting double to String, including in-depth analysis and useful examples to help Java programmers handle this crucial component of programming.

There are the following ways to covert double to String:

  1. Using String.valueOf() Method
  2. Using Double.toString() Method
  3. Using DecimalFormat Class
  4. Using String.format() Method

1. Using String.valueOf() Method

The String.valueOf() method is a static and overloaded method for converting various data types to strings, including doubles. It accepts a double value as input and returns the corresponding string representation.

Example

let us take an example to convert double to string using String.valueOf() Method.

Java

Output:

12.3

Explanation

DoubleToStringExample1 has a main method that acts as the program's starting point. In the main function, a double variable called d is initialized with the value 12.3. The String.valueOf() method is then used to transform the double value d to its string representation, which is stored in the variable s. Finally, the string s is printed to the console using the System.out.println() method.

2. Using Double.toString() Method

Another approach to converting doubles to strings is through the Double.toString() method. This static method of the Double class takes a double value as input and returns its string representation.

Example

let us take an example to convert double to string using Double.toString() Method.

Java

Output:

89.7

Explanation

The code defines DoubleToStringExample2, and the main method of this class serves as the program's entry point. Within the main function, a double variable named d is initialized. The Double.toString() method is then used to translate this double value (d) into its corresponding string representation; the resultant string representation is stored in the variable s. This code explains how to quickly and easily convert a double value to a string using Java's Double.toString() API.

3. Using DecimalFormat Class

An alternative method involves utilizing the DecimalFormat class to achieve custom formatting when converting double values to strings. This approach allows developers to specify specific formatting patterns for numeric values.

Example

let us take an example to convert double to string using decimalformat class.

Java

Output:

123.46

Explanation

This bit of code gives the double value 'd' the value 123.456. Next, a new instance of the class DecimalFormat 'df' is created, with the formatting pattern "#.##" designating two decimal places. The format() method is then used to convert 'd' to its string representation in line with the formatting pattern that has been supplied. The variable 's' is then used to store the generated string.

4. Using String.format() Method

The String. format() method offers another approach to converting double values to strings with customizable formatting options. This method allows developers to specify formatting patterns similar to printf-style formatting.

Example

let us take an example to convert double to string using string.format() method.

Java

Output:

123.456

Explanation

In this code example, the string representation of the double value 'd' is constructed by creating a StringBuilder object called 'sb'. The toString() function on the StringBuilder object acquires the final string after the double value has been appended to the StringBuilder using the append() method.