rate : Currency;
mod1 : Currency;
mod2 : Currency;
mod_rate : Currency;
rate := 29.90;
mod1 := 0.95;
mod2 := 1.39;
mod_rate := rate * mod1 * mod2;
If you perform this calculation in a calculator, you will get a value 39.45295. Since the Delphi data type Currencyis accurate to only 4 decimal places, it internally rounds the value. My testing shows that it uses Banker rounding, so mod_rate should contain a value 39.4530, however in this particular case it is truncated to 39.4529.
I have 40,000 of these calculations, and all of them are correct, except for the above. Here is an example that rounds:
rate := 32.25;
mod1 := 0.90;
mod2 := 1.15;
This is equal 33.37875on the calculator and according to rounding, Banker will go up to 33.3788what Delphi does.
Can someone shed light on what Delphi is doing here?
Chet