This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author noam christian.heimes, gvanrossum, nascheme, noam, rhettinger, tim.peters 2007-12-17.21:53:19 0.01776359 No <1197928400.58.0.0155950146692.issue1580@psf.upfronthosting.co.za>
Content
```Ok, I think I have a solution!

We don't really need always the shortest decimal representation. We just
want that for most floats which have a nice decimal representation, that
representation will be used.

Why not do something like that:

def newrepr(f):
r = str(f)
if eval(r) == f:
return r
else:
return repr(f)

Or, in more words:

1. Calculate the decimal representation of f with 17 precision digits,
s1, using the system's routines.
2. Create a new string, s2, by rounding the resulting string to 12
precision digits.
3. Convert the resulting rounded string to a new double, g, using the
system's routines.
4. If f==g, return s2. Otherwise, return s1.

It will take some more time than the current repr(), because of the
speed is extremely important one can use "'%f.17' % f". It will
obviously preserve the eval(repr(f)) == f property. And it will return a
short representation for almost any float that has a short representation.

This algorithm I will be glad to implement.

What do you think?```
History
Date User Action Args
2007-12-17 21:53:20noamsetspambayes_score: 0.0177636 -> 0.01776359
recipients: + noam, gvanrossum, tim.peters, nascheme, rhettinger, christian.heimes
2007-12-17 21:53:20noamsetspambayes_score: 0.0177636 -> 0.0177636
messageid: <1197928400.58.0.0155950146692.issue1580@psf.upfronthosting.co.za>