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