• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Crunch numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Crunch numbers
      • From: Andy Wylie <email@hidden>
References: 
 >Crunch numbers (From: email@hidden)

  • Prev by Date: Weird...
  • Next by Date: Re: long path error in Finder -- known bug?
  • Previous by thread: Re: Crunch numbers
  • Next by thread: Re: Crunch numbers
  • Index(es):
    • Date
    • Thread