Skip to content Skip to sidebar Skip to footer

Python Float Formatting Weirdness?

I'm trying to debug two different python scripts that execute very similar code. These scripts set a, which is a simple float. For script 1: ipdb> print sys.version 2.7 (r

Solution 1:

The str representation of a float truncates to 12 digits on Python 2. This is unfortunate. You have to print repr(a) to make sure you see enough precision to uniquely identify the float. There's probably a tiny difference that only shows up after 12 digits.

On Python 3, str and repr produce the same output for floats, so you wouldn't have this problem.


Post a Comment for "Python Float Formatting Weirdness?"