float is a Java data type which can store floating point numbers (i.e., numbers that can have a fractional part). Only 4 bytes are used to store float numbers giving a value range of -3.4028235E+38 to 3.4028235E+38.
A problem with the
double) data type is it suffers from rounding errors:
float rounding = 0.9f - 0.11f; System.out.println(rounding);
gives the output of:
Use the BigDecimal class for precise calculations.
float data types are not used unless memory is an issue and an application needs to store a lot of fractional numbers. The
double is the default data type to use for storing fractional numbers.