[gnome-applets] [invest-applet] fractional cent prices are now shown in preferences, fixes bug #593435
- From: Enrico Minack <eminack src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets] [invest-applet] fractional cent prices are now shown in preferences, fixes bug #593435
- Date: Mon, 5 Jul 2010 11:35:04 +0000 (UTC)
commit 54b4e7ee82c4412351993d4880b2b1974c0b3dbc
Author: Enrico Minack <enrico-minack gmx de>
Date: Mon Jul 5 13:32:21 2010 +0200
[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.
invest-applet/invest/preferences.py | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/invest-applet/invest/preferences.py b/invest-applet/invest/preferences.py
index 65d83dc..66f8fbe 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)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]