[Tutor] rounding up to the nearest penny

Timothy Wilson wilson@visi.com
Wed, 3 Oct 2001 08:25:17 -0500 (CDT)


Hi everyone,

I gave my students a programmig assignment (see
http://www.isd197.org/sibley/cs/icp/assignments/loancalc_html for
specifics) and discovered one small feature that I couldn't figure out (at
least easily).

My impression is that when doing financial calculations dollar amounts are
often rounded up to the nearest penny. The round function does a true
round to the nearest penny. The ceil function doesn't appear to work with
floats.

>>>
>>> amount = 1.342
>>> round(amount, 2)
1.34
>>> import math
>>> math.ceil(amount)
2.0

Any suggestions?

-Tim

--
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com