On Mon, 23 Jun 2014 17:55:50 -0700, buck wrote:
> It used to be that the best way to compare floating point numbers while
> disregarding the inherent epsilon was to use `str(x) == str(y)`. It
> looks like that workaround doesn't work anymore in 3.4.
What inherent epsilon? Can you explain what you mean?
> What's the recommended way to do this now?
>>>> format(.01 + .01 + .01 + .01 + .01 + .01, 'g') == format(.06, 'g')
That's equivalent to doing an implicit round. If all you want to do is
round your calculations, then explicitly round them:
py> x = sum([0.01]*6)
py> y = 0.06
py> round(x, 12) == round(y, 12)
Not that I'm recommending that you do it this way, but an explicit round
is better than using string formatting.
See also this: