[pygtk] floating point precision

Timo timomlists at gmail.com
Tue Mar 8 02:30:11 WST 2011


On 26-02-11 21:13, Johann Schatzer wrote:
> Using TreeStore with "float" column, e.g.
> self.treestore = gtk.TreeStore(float)
>
> the widget shows floating point numbers with a precision of 6 digits, like 34.234566 or 22.000000
>
> How can you get a precision of only 1 or 2 digits, like 34.23 or 22.0 ?
>
I would like to know the same. Here is a simple testcase which 
demonstrates the problem.

Cheers,
Timo

import gtk

MYFLOAT = 12.3456

def main():
     win = gtk.Window()
     win.resize(300, 200)
     win.connect('delete-event', gtk.main_quit)

     liststore = gtk.ListStore(float, float)
     treeview = gtk.TreeView(liststore)
     renderer = gtk.CellRendererText()
     col = gtk.TreeViewColumn("Actual", renderer, text=0)
     treeview.append_column(col)
     col = gtk.TreeViewColumn("Rounded", renderer, text=1)
     treeview.append_column(col)

     liststore.append([MYFLOAT, round(MYFLOAT, 2)])

     win.add(treeview)
     win.show_all()
     gtk.main()

if __name__ == '__main__':
     main()


More information about the pygtk mailing list