Thanks for defending my cause ! I already posted some messages on this
subject but I didn't found a so obvious sample to show the error of using
binary when dealing with money.

I'm lobbying for a decimal internal format for money! values, as in COBOL:
REBOL and COBOL should have more than three letter in common !

Olivier.

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, March 06, 2000 7:15 PM
Subject: [REBOL] Money Trouble?


> Hi folks,
>
> Over the weekend I was playing with the REBOL money! datatype and
discovered
> some problems. Using the REBOL/Core console:
>
> >> x: $10
> == $10.00
>
> >> y: x + .01
> == $10.01
>
> >> y - x
> == $0.00             ;surprising result, displayed value is not correctly
> rounded
>
> We can check what is happening by retreiving the decimal value from the
> money values:
>
> >> dx: second x
> == 10
>
> >> dy: second y
> == 10.01
>
> >> dy - dx
> == 9.99999999999979E-3     ;this is the actual numeric value of y - x, it
> should round to .01
>
> The problem seems to be incorrect or absent rounding of the difference:
>
> >> to-money dy - dx
> == $0.00
>
> Checking when to-money will return .01 vs .00:
>
> >> a: to-money "9.99999999999999934E-3"
> == $0.00
> >> b: to-money "9.99999999999999935E-3"
> == $0.01
>
> Clearly both of these values should round to $.01.
>
> There some other anomalies also:
>
> >> (y - x) * 1.00000000000001
> == $0.00
>
> >> (y - x) * 1.0000000000001
> == $0.01
>
> >> (y - x) * 10                ;displayed result is wrong by a factor of
ten
> == $0.01
>
> >> (y - x) * 100              ;displayed result is correct
> == $1.00
>
> These problems are not due to the round-off intrinsic to decimal values.
> Even in the worst case we have 15 significant digits of precision. The
> example shows incorrect rounding in the 4th significant digit.
>
> I wonder whether others have noticed this problem?
>
> Note: this has been CC'd to feedback as a bug.
>
> Cheers
>
> Larry
>
>

Reply via email to