diff -r bcc3f167a30b Doc/library/locale.rst --- a/Doc/library/locale.rst Fri Oct 17 08:52:20 2014 +0100 +++ b/Doc/library/locale.rst Fri Oct 17 11:30:41 2014 +0200 @@ -387,6 +387,12 @@ ``str(float)``, but takes the decimal point into account. +.. function:: delocalize(string) + + Converts a string to a normalized number, following the + :const:'LC_NUMERIC`settings. + + .. function:: atof(string) Converts a string to a floating point number, following the :const:`LC_NUMERIC` diff -r bcc3f167a30b Lib/locale.py --- a/Lib/locale.py Fri Oct 17 08:52:20 2014 +0100 +++ b/Lib/locale.py Fri Oct 17 11:30:41 2014 +0200 @@ -301,8 +301,8 @@ """Convert float to integer, taking the locale into account.""" return format("%.12g", val) -def atof(string, func=float): - "Parses a string as a float according to the locale settings." +def delocalize(string): + "Parses a string as a normalized number according to the locale settings." #First, get rid of the grouping ts = localeconv()['thousands_sep'] if ts: @@ -311,12 +311,15 @@ dd = localeconv()['decimal_point'] if dd: string = string.replace(dd, '.') - #finally, parse the string - return func(string) + return string + +def atof(string, func=float): + "Parses a string as a float according to the locale settings." + return func(delocalize(string)) def atoi(str): "Converts a string to an integer according to the locale settings." - return atof(str, int) + return int(delocalize(string)) def _test(): setlocale(LC_ALL, "")