Besides the rounding problem, note that you should not expect a float or double to be able to hold numbers of arbitrary precision. A float has about 6 decimal digits of precision, and a double about 15 digits. Floats and doubles are stored as binary fractions and they can't represent some decimal numbers to exact precision; for example the number 0.1 cannot be stored in a float or double exactly. Some calculations will inevitably lead to rounding errors.

i think if you require strict floating-point numbers you would need to specify strictfp in either the method or class declaration. wouldnt this give you the exact number? or would you need BigDecimal involved?

dont mind me, i'm new

SCJA, ITIL V3 Foudation, Studying for SCJP6

Max Campa
Greenhorn

Joined: Oct 31, 2009
Posts: 10

posted

0

Hi Rob,

I just posted the code to understand the rules of rounding double primitive types.