Re: Crunch numbers
Re: Crunch numbers
- Subject: Re: Crunch numbers
- From: Deivy Petrescu <email@hidden>
- Date: Fri, 15 Mar 2002 08:50:48 -0500
on 14/3/02 9:02 AM, Deivy Petrescu at email@hidden wrote:
(round (z * (10 ^ numdigits)) rounding as taught in school) * (10 ^
numdigits)
div (10 ^ n) / (10 ^ numdigits)
no good system 8.6, any ideas?
display dialog z & " must be a number and " &
have you really got an auto string coercion there Deivy?
_____________________________ Andy
I am posting this just to show a different approach (Nigel's handler
does the same thing) and because I thought I've replied.
No did not try the coercion, if I did, I'd seen it doesn't work.
Here is the script (following Nigel's I'm putting truncate or not,
leave it out if it is unnecessary).
set z to 1.59999
set truncate to true
ndigits(z, 3, truncate)
to ndigits(z, n, truncate)
try
set n to (n + 2) as integer
set z to (z * (10 ^ n)) div 1
set diff to z mod 100
set z to z - diff
if diff is greater than 49 and not truncate then set
z to z + 100
set z to z / (10 ^ n)
on error
display dialog "" & z & " must be a number and " & n
& " must be an integer" buttons {"OK"} default button 1
error number -128
end try
return z
end ndigits
--
Deivy Petrescu
http://www.dicas.com
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.