RE: limiting decimal places...
RE: limiting decimal places...
- Subject: RE: limiting decimal places...
- From: Jonathan Simms <email@hidden>
- Date: Wed, 22 Nov 2000 21:43:50 -0500
Thanks for the suggestion. I hadn't thought of that!
Can I ask a silly question? How did you know that?
You said "(and according to standards)" what standards are those?
(I know I'm displaying my ignorance openly, please be gentle :-) )
thanks,
Jonathan
>
>
Message: 5
>
Date: Wed, 22 Nov 2000 16:27:38 -0800
>
To: <email@hidden>
>
From: John W Baxter <email@hidden>
>
Subject: Re: Limiting Decimal Places in a Floating Variable?
>
>
At 8:24 -0500 11/22/00, Jonathan Simms wrote:
>
> I'm trying to come up with a running balance for a list of numbers (like a
>
> check book).
>
> The list of numbers are all to 2 decimal places. What's bizarre is that
>
> applescript does fine (adds to the correct number of places) and then
>
> returns values like -2134.2399999 for no apparent reason
>
>
>
> The nines don't really bother me, as all of the numbers to the left of the
>
> nines are correct, I just want to know how to limit the number to 2 decimal
>
> places.
>
>
>
> (although it is kind of interesting considering that there is an error being
>
> added somewhere along the line...would a comma make a difference i.e.
>
>
>
> is 9000.00 different from 9,000.00 ?)
>
>
It's really not a good thing to deal with decimal currency in floating
>
point. It is better to keep an integer number of cents (or mils, in some
>
applications), and write a formatting routine for output. Of the one
>
hundred possible cents values in a dollar, only four (.00, .25, .50, .75)
>
are represented precisely in binary floating point implemented in the usual
>
way (and according to standards).
>
>
And you can't keep terribly large dollar amounts that way in AppleScript,
>
which uses fewer than the obvious 32 bits to represent integers.
>
>
--John
>
--
>
John Baxter email@hidden Port Ludlow, WA, USA