Friday, November 21, 2025
HomeLanguagesJavaHow to Convert a Double value to String value in Java with...

How to Convert a Double value to String value in Java with Examples

Given a Double value in Java, the task is to convert this double value to string type.

Examples:

Input: 1.0
Output: "1.0"

Input: 3.14
Output: "3.14"

Approach 1: (Using + operator)
One method is to create a string variable and then append the double value to the string variable. This will directly convert the double value to string and add it in the string variable.

Below is the implementation of the above approach:

Example 1:




// Java Program to convert double value to String value
  
class GFG {
  
    // Function to convert double value to String value
    public static String
    convertDoubleToString(double doubleValue)
    {
  
        // Convert double value to String value
        // using + operator method
        String stringValue = "" + doubleValue;
  
        return (stringValue);
    }
  
    // Driver code
    public static void main(String[] args)
    {
  
        // The double value
        double doubleValue = 1;
  
        // The expected string value
        String stringValue;
  
        // Convert double to string
        stringValue
            = convertDoubleToString(doubleValue);
  
        // Print the expected string value
        System.out.println(
            doubleValue
            + " after converting into string = "
            + stringValue);
    }
}


Output:

1.0 after converting into string = 1.0

Approach 2: (Using String.valueOf() method)
The simplest way to do so is using valueOf() method of String class in java.lang package. This method takes the double value to be parsed and returns the value in String type from it.

Syntax:

String.valueOf(doubleValue);

Below is the implementation of the above approach:

Example 1:




// Java Program to convert double value to String value
  
class GFG {
  
    // Function to convert double value to String value
    public static String
    convertDoubleToString(double doubleValue)
    {
  
        // Convert double value to String value
        // using valueOf() method
        return String.valueOf(doubleValue);
    }
  
    // Driver code
    public static void main(String[] args)
    {
  
        // The double value
        double doubleValue = 1;
  
        // The expected string value
        String stringValue;
  
        // Convert double to string
        stringValue
            = convertDoubleToString(doubleValue);
  
        // Print the expected string value
        System.out.println(
            doubleValue
            + " after converting into string = "
            + stringValue);
    }
}


Output:

1.0 after converting into string = 1.0
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11995 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS