19 January 2007 @ 12:40Rounding to the nearest even number

I was looking for a way to have an AppleScript round a number to the nearest even, whole number. I did some googling and found some examples of rounding with AppleScript, but I had to modify them to do exactly what I wanted. Here is what I came up with:

property this_number : ""
display dialog "Enter a number" default answer this_number
set the this_number to text returned of result
set rounded to (round (this_number) rounding up)
if rounded mod 2 is not 0 then
set evenNum to (rounded - 1)
else
set evenNum to rounded
end if

Share this:
  • E-mail this story to a friend!
  • Print this article!
  • Wists
  • del.icio.us
  • Reddit
  • Digg
  • StumbleUpon
  • Slashdot
  • Technorati
  • SphereIt
  • Sphinn
  • Google
  • Facebook
  • NewsVine
  • Furl
  • YahooMyWeb
  • Pownce
  • TwitThis
  • Shop Apple
  • Shop Dell

 

Related posts

by Jon | Tags: , ,
Posted in applescript

Link to this post

HTML
BBCode

Add a Comment

 

Sign up for PayPal and start accepting credit card payments instantly.

Get fed!

rss icon subscribe to Geek stuff

rss icon Geek stuff in your inbox

Add the "Geek stuff" Google Gadget to your homepage

Add the "Daily Deals" Google Gadget to your homepage

Featured Tee

UneeTee.com

One Day, One Artist, One cool T-shirt

Overgrown by Jack
Guys - $12
Girls - $12

Apparel

Search Amazon

Search Amazon.com
Search Amazon.co.uk

Advert

Web hosting by ICDSoft