Q:

Conversion from Double to String in Java

belongs to collection: Java Conversion Programs

0

Given a double value and we have to convert it into string.

Java conversion from Double to String

To convert a Double to String, we use toString() method of Double class, it accepts a double value and returns the string value.

Syntax:

    Double.toString(double);

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Java code to convert a Double to String

//Java code to convert a double to String
public class Main {
    public static void main(String args[]) {
        double a = 10;
        double b = 20;

        //variable to store result
        String result = null;

        //converting double to string
        result = Double.toString(a);
        System.out.println("result (value of a as string) = " + result);

        result = Double.toString(b);
        System.out.println("result (value of b as string) = " + result);
    }
}

Output

result (value of a as string) = 10.0
result (value of b as string) = 20.0

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Conversion from Long to String in Java... >>
<< Conversion from Integer to String in Java...