Decimals to fraction strings

François Pinard pinard at iro.umontreal.ca
Tue May 16 22:49:54 EDT 2000


mjackson at wc.eso.mc.xerox.com (Mark Jackson) writes:

> > Yet your suggestion is straightforward, it might not always yield the
> > "best" answer, because of the constraint put on the denominator to
> > initially be an exponent of 10.

> <dumb look>
> Is not this same constraint applied by the problem itself, which starts
> with a [finite length] decimal representation?
> </dumb look>

Not necessarily.  0.6667 is well approximated by 1:3, for example, while
if you force the denominator to be an exponent of 10, you will obtain a
fraction which is not only uglier, but less precise.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list