[Info-vax] VMS Software Q1 '23 Update
Arne Vajhøj
arne at vajhoej.dk
Sat Jan 28 17:35:11 EST 2023
On 1/28/2023 3:01 PM, Steven Schweda wrote:
>> Consider the case where the numbers represent money.
>
> Who cares what the numbers represent? For example, if you round to
> the nearest integer, then 1.49999 and 1.50001 differ by only 0.00002,
> but one rounds to 1, and the other to 2, so the lame test says that
> they're "unequal". And 1.50001 and 2.49999 differ by 0.99998, but they
> both round to 2, so the lame test says that they're "equal". Any test
> which treats a difference of 0.00002 as significant, and a difference of
> 0.99998 as negligible, is, I claim, (obviously) a bad test, regardless
> of what the numbers might represent.
There are some specific rules for money usually about
always rounding 2 digits.
1494 dollars divided by 1000 = 1.494 get rounded to 1.49
diff 0.002 not equal
1496 dollars divided by 1000 = 1.496 get rounded to 1.50
1496 dollars divided by 1000 = 1.496 get rounded to 1.50
diff 0.008 equal
1504 dollars divided by 1000 = 1.504 get rounded to 1.50
Arne
PS: One should never use traditional binary based floating
point for storing money instead use some decimal based
type. But sometimes calculations switch to floating point
anyway.
More information about the Info-vax
mailing list