Menu ▾ ▴

#3 Patch for fixedpoint to respect locale settings

open
nobody
5
2004-05-10
2004-05-10
No

fixedpoint is currentyl "locale agnostic"

That is: here in Germany the decimal_point is comma.
Fixedpoint ignores it and is so basically useless when
converting strings to fixedpoint (no, replace(",",".")
is not an option)

The following patch around _parser can fix this issue.

Open Issue locale must be set before importing
fixedpoint. Getting dynamic changes would require
re-compiling the parser string.

New Code:

import locale

_t=r"""
\s*
(?P<sign>[-+])?
(
(?P<int>\d+) (\%(decimal_point)s (?P<frac>\d*))?
|
\%(decimal_point)s (?P<onlyfrac>\d+)
)
([eE](?P<exp>[-+]? \d+))?
\s* $
""" % locale.localeconv()

_parser = re.compile(_t, re.VERBOSE).match

del re
del locale

Discussion


Log in to post a comment.