Re: rounding integers
Re: rounding integers
- Subject: Re: rounding integers
- From: "Marc K. Myers" <email@hidden>
- Date: Fri, 31 Oct 2003 14:46:12 -0500
Date: Fri, 31 Oct 2003 10:08:01 -0600
Subject: rounding integers
From: Chet Goetz <email@hidden>
To: email@hidden
Please forgive me if this has been discussed (I haven't been able to
find it so far)
I'm making a script that takes a price ($) and multiplies it by 3
percentages and then lists the discounted prices (*.94, *.75, and
*.56). (We give quantity discounts on some parts, but not all.)
I'd like the user to be able to input a price in a dialog box (no
problems there) and then get back a dialog that has the discounted
prices (no problems there, either). However, I get numbers that need to
be rounded to the hundredth place (19.95 instead of 19.948). I've read
about how to round up/down/toward zero/as taught in school, but that
seems to get rid of the decimals entirely.
Would someone be able to get me started on how to round a number to two
decimals?
This should point you in the right direction:
set x to text returned of (display dialog "Input a price" default
answer "")
set a to rndPct(x, 0.94)
set b to rndPct(x, 0.75)
set c to rndPct(x, 0.56)
display dialog a & return & b & return & c
on rndPct(Nbr, Pct)
return ((round ((Nbr * 100) * Pct) rounding up) / 100) as string
end rndPct
Marc [10/31/03 2:45:23 PM]
_______________________________________________
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.