[Info-vax] VMS Software Q1 '23 Update
Dave Froble
davef at tsoft-inc.com
Sat Jan 28 20:16:08 EST 2023
On 1/28/2023 5:35 PM, Arne Vajhøj wrote:
> 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.
For maybe 45 years I've used FP (D-float) for monetary transactions and storage.
Never any problems. The secret is understanding what one is doing.
It is not always simple. Consider products with cost and prices using thousands
and even ten thousands, ie; .001 or .0001. Think of things such as golf tees,
sold by the bag, or rather large quantities. The final calculations will be
less than $.01 off, but that is acceptable. Now, sales analysis, where perhaps
millions of items are considered, can get off a bit. Usually acceptable. But,
rounding will cause some small discrepancies.
Yes, I can understand situations where D-float just won't do the job.
--
David Froble Tel: 724-529-0450
Dave Froble Enterprises, Inc. E-Mail: davef at tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA 15486
More information about the Info-vax
mailing list