[Tutor] rounding up to the nearest penny
Michael P. Reilly
arcege@speakeasy.net
Wed, 3 Oct 2001 10:15:02 -0400
On Wed, Oct 03, 2001 at 08:25:17AM -0500, Timothy Wilson wrote:
> 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 wi=
th
> floats.
The ceil function is based on the C library function. From the manpage:
The ceil() function rounds x upwards to the nearest inte=AD
ger, returning that value as a double.
Since a lot of applications don't use ceil a lot, and there is a standard
math solution to get non-whole unit answers, it probably wasn't deemed
necessary to get add that functionality.
>>> amount =3D 1.342
>>> hundredths =3D 100
>>> import math
>>> math.ceil(amount * hundredths) / hundredths
1.35
>>>
Unfortunately, you can't get the string formats to do the ceiling
function, but they can do the floor function.
Good luck.
-Arcege
--=20
+----------------------------------+-----------------------------------+
| Michael P. Reilly | arcege@speakeasy.net |
| Ailment info: http://www.speakeasy.org/~arcege/michaelwatch.html |