Double.toString() in Java

Double.toString(): This method is available in java.lang.Double class of Java.

Syntax:

String java.lang.Double.toString(double d)

This method takes one argument of type double as its parameter. This method returns a string representation of the double argument.

Note:

1. If the argument is NaN, the result is the string"NaN".

2. Otherwise, the result is a string that represents the sign and magnitude (absolute value) of the argument.

Parameters: One parameter is required for this method.

d: the double to be converted.

Returns: a string representation of the argument.

For Example:

double d = 1919.5

Double.toString(d) = > It returns 1919.5

Approach

Java

public class DoubletoString {
    public static void main(String[] args) {

        double d = 1919.5;
        System.out.println(Double.toString(d));

    }
}

Output:

1919.5

No comments:

Post a Comment