diff --git a/index.html b/index.html index 62f8ccf..a2e1c54 100644 --- a/index.html +++ b/index.html @@ -452,7 +452,7 @@ x = new BigDecimal("1.20") y = new BigDecimal("3.45000") z = x.multiply(y) // 4.1400000
To specify the precision of a value is to specify that the value lies within a certain range.
In the first example, x
has a value of 1.0
. The trailing zero shows the precision of the value, implying that it is in the range 0.95
to 1.05
. Similarly, the precision indicated by the trailing zeros of y
indicates that the value is in the range 1.09995
to 1.10005
.
If we add the two lowest values in the ranges we have, 0.95 + 1.09995 = 2.04995
, and if we add the two highest values we have, 1.05 + 1.10005 = 2.15005
, so the range of the result of the addition implied by the precision of its operands is 2.04995
to 2.15005
.
The result given by BigDecimal of 2.1000
however, indicates that the value is in the range 2.09995
to 2.10005
and therefore the precision implied by its trailing zeros may be misleading.
In the second example, the true range is 4.122744
to 4.157256
yet the BigDecimal answer of 4.1400000
indicates a range of 4.13999995
to 4.14000005
. Again, the precision implied by the trailing zeros may be misleading.
This library, like binary floating point and most calculators, does not retain trailing fractional zeros. Instead, the toExponential
, toFixed
and toPrecision
methods enable trailing zeros to be added if and when required.