round down to nearest number
Olive
diolu at bigfoot.com
Fri Feb 10 15:56:44 EST 2012
On Thu, 9 Feb 2012 17:43:58 -0800
Chris Rebert <clp2 at rebertia.com> wrote:
> On Thu, Feb 9, 2012 at 5:23 PM, noydb <jenn.duerr at gmail.com> wrote:
> > hmmm, okay.
> >
> > So how would you round UP always? Say the number is 3219, so you
> > want 3300 returned.
>
> http://stackoverflow.com/questions/17944/how-to-round-up-the-result-of-integer-division/96921
>
> Thus: (3219 + 99) // 100
>
> Slight tangent: Beware negative numbers when using // or %.
This trick work always (even if the entry is a float):
-(-a//100)*100
>>> -(-3219//100)*100
3300
>>> -(-3200.1//100)*100
3300.0
More information about the Python-list
mailing list