Re: round down to nearest number
Alec Taylor <alec.taylor6 <at> gmail.com>
2012-02-10 11:05:39 GMT
o.O
Very nice
On Fri, Feb 10, 2012 at 8:58 PM, Arnaud Delobelle <arnodel <at> gmail.com> wrote:
> On 10 February 2012 06:21, Ian Kelly <ian.g.kelly <at> gmail.com> 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 is that while the "round down" formula
>> works interchangeably for ints and floats, the "round up" formula does
>> not.
>>
>>>>> (3300.5 + 99) // 100 * 100
>> 3300.0
>>
>
> I'm surprised I haven't seen:
>
>>>> 212 - (212 % -100)
> 300
>
(Continue reading)