Java2all.com  

Float





Share This Topic -

Float class :

The float class encapsulates a float value.

It defines several constants the largest and smallest values are stored in MAX_VALUE and MIN_VALUE.

The constant NaN indicates that a value is not a number. If you divide a floating – point number by zero, the result is NaN.

This class defines these constructors:

      Float(float f)

      Float(double d)

      Float(String str)

Here, f and d are float and double types to be encapsulated in a Float object.

str is the string representation of a float value.

EX :

 

 import java.util.*;

public class Float_Demo
{
	public static void main(String args[])
	{
		Float f1 = new Float(123.5626);
		Float f2 = new Float(854.32f);
		Float i = new Float(10);
		System.out.println("Object f1 = " + f1);
		System.out.println("Object f2 = " + f2);
		System.out.println("Minimum Value of Float = " + Float.MIN_VALUE);
		System.out.println("Maximum Value of Float = " + Float.MAX_VALUE);
		System.out.println("Byte value of Float = " + f1.byteValue());
		System.out.println("Short value of Float = " + f1.shortValue());
		System.out.println("Integer value of Float = " + f1.intValue());
		System.out.println("Double value of Float = " + f1.doubleValue());
		System.out.println("(f1==f2) ?= " + f1.equals(f2));
		System.out.println("f1.compareTo(f2) = " + f1.compareTo(f2));
		System.out.println("f1 is not a number = " + i.isNaN());
		
	}
}

 
Output :
 
Object f1 = 123.5626
Object f2 = 854.32
Minimum Value of Float = 1.4E-45
Maximum Value of Float = 3.4028235E38
Byte value of Float = 123
Short value of Float = 123
Integer value of Float = 123
Double value of Float = 123.5625991821289
(f1==f2) ?= false
f1.compareTo(f2) = -1
f1 is not a number = false