Greetings Merchant and Miva Script users,
The behavior described so far actually isn't a math bug. It's just that
there is more to the issue of how computers calculate and store floating
point numbers, and how they use integer operations in floating point
arithmetic. Following is an explanation of this.
Floating point arithmetic introduces an inherent amount of imprecision,
and application writers need to be aware of the implications of using
rounding and integer operations on calculated floating point values.
The expression provided for discussion (100*(1-0.9)) creates a floating
point number *very close to* (but not exactly) 10. The internal floating
point representation when shown to 20 digits of precision is:
9.99999999999999822364e+00. =20
The integer value of this number is 9. In other words, INT and FLOOR
operations on numbers very close to a specific integer value may provide
unexpected- but not incorrect- results. Whereas the integer value of
this number *after* rounding it to two digits of precision (10.00) will
be 10.
The main points to keep in mind are as follows:
1. Miva Script handles floating point arithmetic in the same way as
other programming languages including C, C++, PHP, and others...=20
2. After performing math operations such as price group adjustments,
Miva Merchant rounds to two digits of precision, eliminating the
floating point issue. So in any case, it will yield the correct result
for handling currency.
James Harrell
Director of Software Development
Miva Corporation
<[email protected]>
858-731-4121 Direct
858-731-4200 Fax
858-735-1294 Cellular
=20
Comment