Friday, 9 August 2013

python float formatting weirdness?

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 (r27:82500, Jul 15 2010, 13:04:38)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)]
ipdb> type(a)
<type 'float'>
ipdb> print a
17.23105
ipdb> print '{0:.4f}'.format(a)
17.2311
For script 2:
ipdb> print sys.version
2.7 (r27:82500, Jul 15 2010, 13:04:38)
ipdb> print type(a)
<type 'float'>
ipdb> print a
17.23105
ipdb> print '{0:.4f}'.format(a)
17.2310
How is it possible that a formats differently in the two cases? In what
ways can a possibly differ between the two scripts, if I've already
checked that their value is the same at 17.23105 ? (unfortunately the
python code that originally sets a is very, very long... I wouldn't want
to bore everyone with 1000+ lines)

No comments:

Post a Comment