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)
set evenNum to rounded
end if

Shop for Applescript books

Be Sociable, Share!

by | Add a comment | Tags: , ,
Posted in applescript | Link to this

Add a Comment

Show who you are with a Gravatar.


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

Staples Logo

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


Search Amazon

Search Amazon.com
Search Amazon.co.uk

Recent Forum Topics


    Web hosting by ICDSoft