Skip to content Skip to sidebar Skip to footer

Rounding Up With Python

I've read the following pages: python decimals - rounding to nearest whole dollar (no cents) - with ROUND_HALF_UP http://docs.python.org/library/decimal.html I have the following c

Solution 1:

Can't you use math.ceil? It will do the necessary thing if you are using a float division. Currently you are doing an integer division.

Solution 2:

total is an integer. As such, / is doing integer division. Either divide by 10. (and hope that precision limits don't bite you in the ***), or do your math in Decimal with an appropriate context.

Post a Comment for "Rounding Up With Python"