Loss of precision / data corruption with Tkinter.DoubleVar ?!

Tim Peters tim.one at comcast.net
Fri Apr 11 16:17:01 EDT 2003


[Lonnie Princehouse]
> I stumbled across this curiosity yesterday:
>
> >>> x = 0.33333333333333098
> >>> x
> 0.33333333333333098
> >>> import Tkinter
> >>> y = Tkinter.DoubleVar(Tkinter.Tk())
> >>> y.set(x)
> >>> y.get()
> 0.33333333333300003

Please open a bug report on this.  The result is the same as you'd get via

    float(str(x))

and Python's str() doesn't produce enough significant digits to reproduce
the input double.  A bit of digging revealed that Python's _tkinter.c is
using PyObject_Str() to produce a string to pass on to Tk, and that's the C
spelling of Python's str().  That explains the symptom, but I don't know how
to fix it.  If you open a bug report, someone who does know how to fix it
can be found.






More information about the Python-list mailing list