[kupfer: 5/18] calculator: change localized decimal point symbol to dot



commit 5447d55c8df6419837b06941e284a90c2c4dc1ff
Author: Karol BÄdkowski <karol bedkowski gmail com>
Date:   Sun Jun 10 17:32:59 2012 +0200

    calculator: change localized decimal point symbol to dot

 kupfer/plugin/calculator.py |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/plugin/calculator.py b/kupfer/plugin/calculator.py
index c79260a..65a853f 100644
--- a/kupfer/plugin/calculator.py
+++ b/kupfer/plugin/calculator.py
@@ -11,8 +11,10 @@ Changes:
 		+ calculate action for expression w/o =
 	2012-06-10:
 		+ separate Calculate action
+		+ change localized decimal point symbol to .
 """
 
+import locale
 import cmath
 import math
 
@@ -126,8 +128,9 @@ class Calculate (Action):
 		brackets_missing = expr.count("(") - expr.count(")")
 		if brackets_missing > 0:
 			expr += ")" * brackets_missing
+		# hack: change all decimal points (according to current locale) to '.'
+		expr = expr.replace(locale.localeconv()['decimal_point'], '.')
 		environment = make_environment(self.last_result['last'])
-
 		pretty.print_debug(__name__, "Evaluating", repr(expr))
 		try:
 			result = eval(expr, environment)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]