[TIP] doctest and floats

Rod Hyde rod.hyde at gmail.com
Tue Mar 11 03:51:09 PDT 2008


Is string formatting a solution or is that too simplistic?

>>> def foo(n):
    return n

>>> foo(0.1)
0.10000000000000001
>>> '%3.2f' % foo(0.1)
'0.10'

--- Rod


On Mon, Mar 10, 2008 at 8:58 AM, Tim Head <betatim at gmail.com> wrote:
>
> It feels wrong to write
> >>> foo(0.1)
> 0.10000000000000001
>
> however
>
> >>> foo(0.1)
> 1./10.
>
> does not work either.
>
> Does anyone of you clever people have some experience with how to do
> this properly?



More information about the testing-in-python mailing list