You cannot use float or double without the risk of losing precision. First of all, their accuracy is limited, for float it is approximately 7-8 decimal digits, for double 16 digits. Besides the fact that Java floating point types are internal binary, therefore they cannot store some decimals without loss of precision. If you really need exact decimal fractions, use java.math.BigDecimal. Read Effective Java. Paragraph 48: "Avoid floating and double if accurate answers are required."
source share