Java2all.com  

Double





Share This Topic -

Double class :

The Double class encapsulates a double value. It defines several constants.

The largest and smallest values are saved in MAX_VALUE and MIN_VALUE.

The constant NaN (Not a Number) indicates that a value is not a number.

If you divide a double number by zero, the result is NaN. This class defines these constructors:     

Double(double d)

Double(String str)

Here, d is a double value to be encapsulated in a Double object. In the last form, str is the string representation of a double value.

EX :

 import java.util.*;
class Double_Demo
{
	public static void main(String args[])
	{
		Double d1 = new Double(687642365.4563);
		Double d2 = new Double("686748");
		System.out.println("Object d1 = " + d1);
		System.out.println("Object d2 = " + d2);
		System.out.println("Minimum Value of Double = " + Double.MIN_VALUE);
		System.out.println("Maximum Value of Double = " + Double.MAX_VALUE);
		System.out.println("Byte value of Double = " + d1.byteValue());
		System.out.println("int value of Double = " + d1.intValue());
		System.out.println("Float value of Double = " + d1.floatValue());
		Double d3 = Double.parseDouble("765.89");
		System.out.println("Double value from the string \"765.89\"="+d3);
		
	}
}

 
Output :
 
Object d1 = 6.876423654563E8
Object d2 = 686748.0
Minimum Value of Double = 4.9E-324
Maximum Value of Double = 1.7976931348623157E308
Byte value of Double = -3
int value of Double = 687642365
Float value of Double = 6.8764237E8
Double value from the string "765.89"=765.89