• 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: Rounding real numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rounding real numbers


  • Subject: Re: Rounding real numbers
  • From: Ken Dobson <email@hidden>
  • Date: Sun, 28 Jan 2001 22:00:40 -0500

> Message: 11
> Date: Sun, 28 Jan 2001 16:32:06 -0500
> Subject: Rounding real numbers
> From: giZm0 <email@hidden>
> To: Applescript Mailing List <email@hidden>
>
> Hi,
> i am uing a value qich is representing the amount of bytes of a specific
> file. To get the number in megabytes instead, i worte this:
>
> (thenumber / 1024) / 1024
>
> Now, when i dialog this number it contains about 10 numbers after the point
> (.). For example : 6.022548445
> While i know this is normal, i would like to round this number to two
> decimals only (6.02). Does anyone knows an easy way to do this ?
>
> I could also delete the other decimals, without rounding... btu i dont know
> how
>
> giZm0

Here is a technique that was passed along to me a while back:

set x to 6.022548445
set y to (round (1000 * x)) / 1000 -->6.023
set z to (round (100 * x)) / 100 -->6.02

or stuff it into one line

set x to (round (100 * 6.022548445)) / 100

I use several small subs that round to different places beyond the decimal
point and have proven to be a quick solution for this.


  • Prev by Date: Re: Listing apps in launch order
  • Next by Date: Applescript and Photoshop 6.0
  • Previous by thread: Re: Rounding real numbers
  • Next by thread: Re: Rounding real numbers
  • Index(es):
    • Date
    • Thread