Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristhofer Travieso <cristhofert97@gmail.com>2012-08-22 11:55:59 (GMT)
committer Cristhofer Travieso <cristhofert97@gmail.com>2012-08-22 11:56:19 (GMT)
commitcee6b169f5e60203ddbdc21143022452beba6ebd (patch)
tree862158d0b2017a8dff183e8b1a13f2db05720357
parent74d881ba3d9797e66e368d2d4ee1d222c2d9d7c5 (diff)
Use locale to format the decimal separator
Signed-off-by: Cristhofer Travieso <cristhofert97@gmail.com>
-rw-r--r--activity.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/activity.py b/activity.py
index f6a4809..51c1566 100644
--- a/activity.py
+++ b/activity.py
@@ -16,6 +16,7 @@
import gtk
import pango
+import locale
import convert
from sugar.activity import activity
@@ -150,7 +151,15 @@ class ConvertActivity(activity.Activity):
self.show_all()
def _update_label(self):
- a = '%s ~ %s' % (str(self.spin.get_text()), str(self.convert()))
+ spin_value = str(self.spin.get_value())
+ decimals = str(len(spin_value.split('.')[-1]))
+ new_value = locale.format('%.' + decimals + 'f', float(spin_value))
+
+ convert_value = str(self.convert())
+ decimals = str(len(convert_value.split('.')[-1]))
+ new_convert = locale.format('%.' + decimals + 'f', float(convert_value))
+
+ a = '%s ~ %s' % (new_value, new_convert)
print a
self.label.set_text(a)
@@ -203,7 +212,7 @@ class ConvertActivity(activity.Activity):
pass
def convert(self):
- number = float(self.spin.get_text())
+ number = float(self.spin.get_text().replace(",", "."))
unit = self._get_active_text(self.combo1)
to_unit = self._get_active_text(self.combo2)
return convert.convert(number, unit, to_unit, self.dic)