summaryrefslogtreecommitdiff
path: root/invest-applet
diff options
context:
space:
mode:
authorEnrico Minack <enrico-minack@gmx.de>2010-07-05 13:32:21 +0200
committerEnrico Minack <enrico-minack@gmx.de>2010-07-05 13:32:21 +0200
commit54b4e7ee82c4412351993d4880b2b1974c0b3dbc (patch)
tree46c94ac1773b9f468c863ab4a1f793bb4ad93861 /invest-applet
parent870b26c3854f7cdeb37c49d54a88b988242d4b36 (diff)
[invest-applet] fractional cent prices are now shown in preferences, fixes bug #593435
Fractional cent prices are properly processed by the invest applet, but in the preferences, the configured cents were shown rounded to full cents. This caused confusion, so cents are now shown with at least two digits.
Diffstat (limited to 'invest-applet')
-rw-r--r--invest-applet/invest/preferences.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/invest-applet/invest/preferences.py b/invest-applet/invest/preferences.py
index 65d83dc49..66f8fbe7b 100644
--- a/invest-applet/invest/preferences.py
+++ b/invest-applet/invest/preferences.py
@@ -40,10 +40,21 @@ class PrefsDialog:
if typ == int:
cell.set_property('text', "%d" % typ(model[iter][col]))
elif typ == float:
- cell.set_property('text', "%.2f" % typ(model[iter][col]))
+ # provide float numbers with at least 2 fractional digits
+ val = model[iter][col]
+ digits = fraction_digits(val)
+ format = "%%.%df" % max(digits, 2)
+ cell.set_property('text', format % val)
else:
cell.set_property('text', typ(model[iter][col]))
+ # determine the number of non zero digits in the fraction of the value
+ def fraction_digits(value):
+ text = "%g" % value
+ if text.find(".") < 0:
+ return 0
+ return len(text) - text.find(".") - 1
+
def create_cell (view, column, name, typ):
cell_description = gtk.CellRendererText ()
cell_description.set_property("editable", True)