In Java, the float
data type is a single-precision, 32-bit floating-point data type that represents decimal values with a range of approximately 1.4E-45 to 3.4E+38.
Here's an example of how to declare and use a float
variable in Java:
public class Main { public static void main(String[] args) { float value = 3.14f; // The "f" suffix indicates that the value is a float System.out.println(value); // prints "3.14" } }
The float
data type is smaller and less precise than the double
data type, which is a double-precision, 64-bit floating-point data type. In general, it is recommended to use the double
data type for decimal values unless you have a specific reason to use the float
data type, such as to save memory or to match the precision of an external system.