Table of content

What is float in Java?

The float keyword is a data type that stores fractional or decimal numbers containing one or more decimals. The size of the float data type is 4 bytes.

The float data type is a single-precision 32 bit IEEE 754 floating-point. The float data type should not be used for precise values.

The range of float data type is 3.40282347e+38d to 1.40239846e-45d. The float data type can be used to store 6 to 7 decimal places.

The minimum value float data type can hold is 1.4e-45 and the maximum value is 3.4e+38. The default value of float data type is 0.0f.

It is recommended to use float when the user needs to save memory in large arrays of floating-point numbers.

The declaration of float data type should be terminated with f. For example float x = 7363.4553f;

float x = 56.3892f;
float y = 98.7367f;
float sum = x + y;
System.out.println("Result: "+sum);

The output is

Result: 155.1259
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions