Re: round down to nearest number

2012-02-11 Thread Hrvoje Niksic
Terry Reedy writes: > On 2/9/2012 8:23 PM, noydb wrote: >> So how would you round UP always? Say the number is 3219, so you want (//100+1)*100 > 3400 Note that that doesn't work for numbers that are already round: >>> (3300//100+1)*100 3400# 3300 would be correct I'd go with Chri

Re: round down to nearest number

2012-02-10 Thread Olive
On Thu, 9 Feb 2012 17:43:58 -0800 Chris Rebert wrote: > On Thu, Feb 9, 2012 at 5:23 PM, noydb 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-integ

Re: round down to nearest number

2012-02-10 Thread noydb
On Feb 10, 4:58 am, Arnaud Delobelle wrote: > On 10 February 2012 06:21, Ian Kelly wrote: > > > > > > > (3219 + 99) // 100 * 100 > >> 3300 > > (3289 + 99) // 100 * 100 > >> 3300 > > (328678 + 99) // 100 * 100 > >> 328700 > > (328 + 99) // 100 * 100 > >> 400 > > >> Those are all ro

Re: round down to nearest number

2012-02-10 Thread Alec Taylor
o.O Very nice On Fri, Feb 10, 2012 at 8:58 PM, Arnaud Delobelle wrote: > On 10 February 2012 06:21, Ian Kelly wrote: >> (3219 + 99) // 100 * 100 >>> 3300 >> (3289 + 99) // 100 * 100 >>> 3300 >> (328678 + 99) // 100 * 100 >>> 328700 >> (328 + 99) // 100 * 100 >>> 400 >>> >>> Thos

Re: round down to nearest number

2012-02-10 Thread Arnaud Delobelle
On 10 February 2012 06:21, Ian Kelly wrote: > (3219 + 99) // 100 * 100 >> 3300 > (3289 + 99) // 100 * 100 >> 3300 > (328678 + 99) // 100 * 100 >> 328700 > (328 + 99) // 100 * 100 >> 400 >> >> Those are all rounded up to the nearest 100 correctly. > > One thing to be aware of though

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 8:36 PM, MRAB wrote: > On 10/02/2012 02:25, noydb wrote: >> >> That {>>>  (3219 + 99) // 100} doesnt work if the number is other then >> 4 digits. >> >> >> (for rounding up to nearest 100): > >  (3219 + 99)//100 >> >> 33 > >  (3289 + 99)//100 >> >> 33 > >

Re: round down to nearest number

2012-02-09 Thread MRAB
On 10/02/2012 03:29, Terry Reedy wrote: On 2/9/2012 8:23 PM, noydb wrote: So how would you round UP always? Say the number is 3219, so you want >>> (//100+1)*100 3400 Doing it that way doesn't always work. For example: >>> (3400 // 100 + 1) * 100 3500 However: >>> (3400 + 99) // 1

Re: round down to nearest number

2012-02-09 Thread MRAB
On 10/02/2012 02:25, noydb wrote: That {>>> (3219 + 99) // 100} doesnt work if the number is other then 4 digits. (for rounding up to nearest 100): (3219 + 99)//100 33 (3289 + 99)//100 33 (328678 + 99)//100 3287 (328 + 99)//100 4 >>> (3219 + 99) // 100 * 100 3300 >>> (3289 + 99)

Re: round down to nearest number

2012-02-09 Thread Terry Reedy
On 2/9/2012 8:23 PM, noydb wrote: So how would you round UP always? Say the number is 3219, so you want >>> (//100+1)*100 3400 -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list

Re: round down to nearest number

2012-02-09 Thread noydb
That {>>> (3219 + 99) // 100} doesnt work if the number is other then 4 digits. (for rounding up to nearest 100): >>> (3219 + 99)//100 33 >>> (3289 + 99)//100 33 >>> (328678 + 99)//100 3287 >>> (328 + 99)//100 4 -- http://mail.python.org/mailman/listinfo/python-list

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 6:43 PM, Chris Rebert wrote: > On Thu, Feb 9, 2012 at 5:23 PM, noydb 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-divis

Re: round down to nearest number

2012-02-09 Thread Chris Rebert
On Thu, Feb 9, 2012 at 5:23 PM, noydb 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 ne

Re: round down to nearest number

2012-02-09 Thread Chris Kaynor
On Thu, Feb 9, 2012 at 5:40 PM, Chris Kaynor wrote: > On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: > >> hmmm, okay. >> >> So how would you round UP always? Say the number is 3219, so you want >> 3300 returned. >> > > You may want to look into the mathematical floor and ceiling functions[1]. > Py

Re: round down to nearest number

2012-02-09 Thread Chris Kaynor
On Thu, Feb 9, 2012 at 5:23 PM, noydb wrote: > hmmm, okay. > > So how would you round UP always? Say the number is 3219, so you want > 3300 returned. > You may want to look into the mathematical floor and ceiling functions[1]. Python exposes them in the math module as floor and ceil[2]. [1] ht

Re: round down to nearest number

2012-02-09 Thread noydb
hmmm, okay. So how would you round UP always? Say the number is 3219, so you want 3300 returned. -- http://mail.python.org/mailman/listinfo/python-list

Re: round down to nearest number

2012-02-09 Thread Ian Kelly
On Thu, Feb 9, 2012 at 5:30 PM, noydb wrote: > How do you round down ALWAYS to nearest 100?  Like, if I have number > 3268, I want that rounded down to 3200.  I'm doing my rounding like round(3268, -2) > But, how to round DOWN? >>> 3268 // 100 * 100 3200 For more complicated cases, Decimal

round down to nearest number

2012-02-09 Thread noydb
How do you round down ALWAYS to nearest 100? Like, if I have number 3268, I want that rounded down to 3200. I'm doing my rounding like >>> round(3268, -2) But, how to round DOWN? -- http://mail.python.org/mailman/listinfo/python-list