• 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: How can I round in applescript to 3 digits after a period?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I round in applescript to 3 digits after a period?


  • Subject: Re: How can I round in applescript to 3 digits after a period?
  • From: "Mark J. Reed" <email@hidden>
  • Date: Thu, 3 Jan 2008 12:57:03 -0500

I.e. 19.9898923978923892 should just be rounded to 19.989

That's not rounding, that's truncating.  19.9898 rounds to 19.990.
 
Also 19.0909 should just be rounded to 19.989

You mean 19.091?

 
Per what I understand rounding in applescript rounds to an integer so is there
a different rounding method that I can use to round to three digits after the
period?
 
The usual method to get more precision is to multiply by a power of 10 so that all the digits you want to keep are to the left of the decimal, then convert to an integer, and then divide by that power of 10 again.  For example:

set origNum to 19.989892397892
set roundedNum to ((origNum * 1000) as integer) / 1000.0
-- 19.99


--
Mark J. Reed <email@hidden >
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: How can I round in applescript to 3 digits after a period?
      • From: Doug McNutt <email@hidden>
References: 
 >How can I round in applescript to 3 digits after a period? (From: "Patrik B." <email@hidden>)

  • Prev by Date: Re: Dates
  • Next by Date: Re: Hi...
  • Previous by thread: Re: How can I round in applescript to 3 digits after a period?
  • Next by thread: Re: How can I round in applescript to 3 digits after a period?
  • Index(es):
    • Date
    • Thread