Curious Omission In New-Style Formats

Chris Angelico rosuav at gmail.com
Wed Jul 13 09:49:56 EDT 2016


On Wed, Jul 13, 2016 at 11:16 PM, Jussi Piitulainen
<jussi.piitulainen at helsinki.fi> wrote:
>> Or just use divmod:
>>
>>>>> "%d.%02d" % divmod(1<<200, 100)
>> '16069380442589902755419620923411626025222029937827928353013.76'
>
> I'm not quite ready to blame floating point for this difference yet:
>
>>>> "%d.%02d" % divmod(-1,100)
> '-1.99'
>>>> "%.2f" % (-1/100)
> '-0.01'

Ehhhh, forgot about that :D Negative numbers and modulo *always* trip
me up, because different languages have different rules. I inevitably
have to go check the docos.

ChrisA



More information about the Python-list mailing list