Java Float Program Example

Chapter: Data Types Last Updated: 28-03-2017 17:41:10 UTC

Program:

            /* ............... START ............... */
                
public class JavaFloatExample {
	public static void main(String[] args) {

		float f = 34.4f;
		System.out.println("Value of float variable f is :" + f);

		// returns the float value represented by this float object
		Float obj = new Float("20.36f");
		float f1 = obj.floatValue();
		System.out.println("Value = " + f1);

		obj = new Float("10.00");
		f1 = obj.floatValue();
		System.out.println("Value = " + f1);
	}
}
                /* ............... END ............... */
        

Output

Value of float variable f is :34.4
Value = 20.36
Value = 10.0

Notes:

  • Float is 32 bit single precision type and used when fractional precision calculation is required.
  • float <variable name> = <default value>;
  • The float data type is a single-precision 32-bit IEEE 754 floating point.
  • Float data type is 4 bytes, IEEE 754. Covers a range from 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative).

Tags

Java, Float

Similar Programs Chapter Last Updated
Java String Example Program Data Types 19-06-2016
Primitive Datatypes In Java Example Data Types 17-06-2016
Enum In Java Example Data Types 28-04-2016
Java Short Example Program Data Types 10-06-2016
Java Long Example Program Data Types 15-07-2016
Java Int Example Program Data Types 06-07-2016
Int Array In Java Example Program Data Types 09-06-2016
Java Double Example Program Data Types 28-03-2017
Java Char Example Program Data Types 28-03-2017
Java Byte Example Program Data Types 28-03-2017
Java Boolean Example Program Data Types 28-03-2017

1