Hi,

I want to present a different point of view. My experiences are,
that the binary representation is as good as the BCD for the
accounting purposes. I do have an accounting program in Rebol
using Decimal! as its basic type.

If you want to be exact, you shall always be careful of what you
are doing and BCD can be no replacement for brains eg in Euro
conversions (three or more decimal digits are needed for
intermediate results) or some average computations.

The BCD is more convenient only in the cases where the operations
don't
yield results with infinite number of decimal places, or results
with more decimal places, than the program should process. For
the more complicated cases it's simply the programmer's task to
take care.

a part of my accounting program:

round: func ["Round a number"
    n [number!]
    p [integer!] {Decimal places - can be negative}
    /local factor r
] [
    factor: 10 ** (- p)
    n: 0.5 * factor + n
    n - either negative? r: n // factor [factor + r] [r]
]

add-m: func [a [number!] b [number!]] [
    round a + b 2
]

sub-m: func [a [number!] b [number!]] [
    round a - b 2
]

(the above doesn't mean, that I consider the "rounding" of Money!
values in Rebol to be correct)

Just my $0,021
    Ladislav

> 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