floor() function and mathematical integers

Tim Peters tim.one at home.com
Fri May 25 18:22:15 EDT 2001

[Aahz Maruch]
> ...
> For comparison, take a look at this routine from Tim Peters to convert
> floats to strings (yes, Tim, I modified it to work with 1.5.2):

Not quite:

> ....
>     return "%s%de%d" % (sign, top, e)

They're you're in trouble in 1.5.2:  top can be a large integer indeed, and
1.5.2 can't convert an unbounded int via %d.  You would have discovered that
had you tested it <wink>.  Try this instead:

    return "%s%se%d" % (sign, repr(top)[:-1], e)

The "-1" slicing is to get rid of the trailing "L".

More information about the Python-list mailing list