[Zope3-checkins] SVN: Zope3/trunk/src/zope/i18n/ Fixed two bugs in
the numer parsing code. Thanks goes to Sven Schomaker for
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu May 26 15:22:41 EDT 2005
Log message for revision 30517:
Fixed two bugs in the numer parsing code. Thanks goes to Sven Schomaker for
pointing them out.
Changed:
U Zope3/trunk/src/zope/i18n/format.py
U Zope3/trunk/src/zope/i18n/tests/test_formats.py
-=-
Modified: Zope3/trunk/src/zope/i18n/format.py
===================================================================
--- Zope3/trunk/src/zope/i18n/format.py 2005-05-26 19:00:11 UTC (rev 30516)
+++ Zope3/trunk/src/zope/i18n/format.py 2005-05-26 19:22:11 UTC (rev 30517)
@@ -277,9 +277,10 @@
type = int
if self.symbols['decimal'] in num_str:
type = float
+ num_str = num_str.replace(self.symbols['decimal'], '.')
if self.symbols['exponential'] in num_str:
type = float
- num_str.replace(self.symbols['exponential'], 'E')
+ num_str = num_str.replace(self.symbols['exponential'], 'E')
return sign*type(num_str)
def _format_integer(self, integer, pattern):
Modified: Zope3/trunk/src/zope/i18n/tests/test_formats.py
===================================================================
--- Zope3/trunk/src/zope/i18n/tests/test_formats.py 2005-05-26 19:00:11 UTC (rev 30516)
+++ Zope3/trunk/src/zope/i18n/tests/test_formats.py 2005-05-26 19:22:11 UTC (rev 30517)
@@ -944,6 +944,15 @@
self.assertEqual(self.format.parse('(4.102E1 ) ', '(0.0##E0##* )* '),
41.02)
+ def testParseDecimalWithGermanDecimalSeparator(self):
+ format = NumberFormat(symbols={'decimal': ',', 'group': '.'})
+ self.assertEqual(format.parse('1.234,567', '#,##0.000'), 1234.567)
+
+ def testParseWithAlternativeExponentialSymbol(self):
+ format = NumberFormat(
+ symbols={'decimal': '.', 'group': ',', 'exponential': 'X'})
+ self.assertEqual(format.parse('1.2X11', '#.#E0'), 1.2e11)
+
def testFormatSimpleInteger(self):
self.assertEqual(self.format.format(23341, '###0'),
'23341')
More information about the Zope3-Checkins
mailing list