Re: Limiting Decimal Places in a Floating Variable?
Re: Limiting Decimal Places in a Floating Variable?
- Subject: Re: Limiting Decimal Places in a Floating Variable?
- From: Nigel Garvey <email@hidden>
- Date: Thu, 23 Nov 2000 11:34:40 +0000
Michelle Steiner wrote on Wed, 22 Nov 2000 09:19:24 -0800:
>
On 11/22/00 5:24 AM, Jonathan Simms <email@hidden> 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.
>
>
set x to -2134.2399999
>
set x to (round (x * 100) rounding toward zero) / 100
Just out of curiosity, does this work with the number 8348.39 on your
machine? Or 8348.29? Or several other fractional numbers in the range
+/-(8192.xx to 9999.xx)? In Mac OS 8.6, these numbers can't be directly
represented to 2 decimal places at all by AppleScript. They have to be
multiplied by 100, rounded, coerced to string at that point, and then the
string doctored to place the decimal point. I think that's what this
thread may be about, though -2134.23 isn't actually one of the problem
numbers.
Incidentally, if you're in the market for a really fast way of
multiplying by 100 and rounding towards zero:
x div 0.01
NG