Example of Methods to Convert double to String in Java

Below is the implementation of Methods to Convert double to String:

Java




// Java Program to Convert
// Double Data to a String Data
 
// Importing Libraries
import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
 
// Driver Class
class GFG {
    // Main driver function
    public static void main(String[] args)
    {
        // Declaring and initializing double number
        double number = 123.456;
 
        // Converting Double data to String data
        String method1 = String.valueOf(number);
        System.out.println("Using valueOf method "
                           + method1);
 
        // Conversion using format()
        String method2 = String.format("%f", number);
        System.out.println("Using format method "
                           + method2);
 
        // Conversion using append()
        String method3
            = new StringBuilder().append(number).toString();
        System.out.println("Using append method "
                           + method3);
 
        // Converting Double data to String data
        String method4 = Double.toString(number);
        System.out.println("Using toString method "
                           + method4);
 
        // Converting using DecimalFormat
        String method5
            = DecimalFormat.getNumberInstance().format(
                number);
        System.out.println("Using Decimalformat method "
                           + method5);
    }
}


Output

Using valueOf method 123.456
Using format method 123.456000
Using append method 123.456
Using toString method 123.456
Using Decimalformat method 123.456


Java Program to Convert Double to String

The primary goal of double to String conversion in Java is to store big streams of numbers that are coming where even data types fail to store the stream of numbers. It is generically carried out when we want to display the bigger values. In this article, we will learn How to Convert double to String in Java.

Similar Reads

Program to Convert double to String in Java

Below is the implementation of double to String conversion using ‘+’ :...

Different Methods for Converting double to String in Java

...

Example of Methods to Convert double to String in Java

There are different kinds of methods to convert double data to string data. Two standard approaches are as follows:...

Contact Us