Rounding up to the next 100

casevh casevh at gmail.com
Fri Jan 22 00:02:44 EST 2010


On Jan 21, 1:58 pm, noydb <jenn.du... at gmail.com> wrote:
> Sorry, although what I really need is the string-number rounded UP
> every time.  So if the number is 3890.32, it needs to go to 3900; if
> the number is 3811.345, it needs to go to 3900 also.
>
> So, Florian's answer works.

Another option is using math.ceil and math.floor.

>>> import math
>>> 100*math.ceil(1234.5678/100)
1300
>>> 100*math.floor(1234.5678/100)
1200
>>> 100*math.ceil(-1234.5678/100)
-1200
>>> 100*math.floor(-1234.5678/100)
-1300

casevh



More information about the Python-list mailing list