# double behaviour

Sethu Prem

Greenhorn

Posts: 6

Jean-Sebastien Abella

Ranch Hand

Posts: 60

posted 10 years ago

This is a very old problem with floating point. If you want exact value you must use BigDecimal.

This is due to a limitation in the value you can represent on a bit pattern as there is an infinite number of decimal value between 0 and 1 there is a need for some imprecision.

This is due to a limitation in the value you can represent on a bit pattern as there is an infinite number of decimal value between 0 and 1 there is a need for some imprecision.

Paul Santa Maria

Ranch Hand

Posts: 236

posted 10 years ago

Jean-Sebastien is, of course, absolutely right. The key two points are:

1. Floating point math is an *approximation* (integer and BigDecimal is

*exact*)

... and ...

2. The order you perform the individual calculations affects what

values the intermediate results round to, which in turn affects the

final result.

EXAMPLE:

1. Floating point math is an *approximation* (integer and BigDecimal is

*exact*)

... and ...

2. The order you perform the individual calculations affects what

values the intermediate results round to, which in turn affects the

final result.

EXAMPLE:

Paul M. Santa Maria, SCJP