• 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 numbers in Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rounding numbers in Applescript


  • Subject: Re: Rounding numbers in Applescript
  • From: Graff <email@hidden>
  • Date: Thu, 08 Jul 2004 16:27:22 -0400

Just multiply by 100, round and then divide by 100. That way you will round to the hundredths place rather than the ones place:
----
-- the coercion is needed just for this example because
-- Script Editor trims numbers when the script is compiled

set aNum to "10.2499999999999" as real
(round (aNum * 100)) / 100

--> 10.25
----

This example will round to the nearest hundredths place (nearest even hundredths place if exactly between two of them).

- Ken

On Jul 8, 2004, at 3:52 PM, PiercyWorld wrote:

Hi, I was wondering what the code would be to get a number to round to
10.25 when the number is 10.2499999999999

I am having image Events get the height and width of a file but it
sometimes returns a long number. All I wan is the first 2 before the
decimal and the second 2 after the decimal.

Here is what I have so far.

set image_height to round (image_height / image_DPI) rounding up as text

this will only return the first 2 numbers. So, the above number gets
returned as 10 instead of 10.25.
_______________________________________________
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.


References: 
 >Rounding numbers in Applescript (From: PiercyWorld <email@hidden>)

  • Prev by Date: Re: AS asking for application on every occasion
  • Next by Date: Re: Sorting a list of Lists
  • Previous by thread: Rounding numbers in Applescript
  • Next by thread: Changing screen resolutions - updated
  • Index(es):
    • Date
    • Thread