Re: Crunch numbers
Re: Crunch numbers
- Subject: Re: Crunch numbers
- From: Deivy Petrescu <email@hidden>
- Date: Wed, 13 Mar 2002 15:02:51 -0500
At 14:57 +0100 3/13/02, email@hidden wrote:
Hi all,
How do I get the nearest value?
set x to "2,84"
set y to "135,7"
y / x
--Result: 47.781690140845
--Crunch this number to the nearest highest value "47,8"
Best regards
Peter Mathiessen
Peter
this handler does what you want:
set x to "2.84"
set y to "135.7"
set z to y / x
ndigits(z, 2)
to ndigits(z, numdigits)
try
set numdigits to numdigits as integer
set z to (round (z * (10 ^ numdigits)) rounding as
taught in school) * (10 ^ numdigits) div (10 ^ n) / (10 ^ numdigits)
-- no line wrapping
on error
display dialog z & " must be a number and " &
numdigits & "must be an integer" buttons {"OK"} default button 1 --
no line wrapping
error number -128
end try
return z
end ndigits
--> 47.78
Regards
--
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.