Created
February 3, 2013 06:03
-
-
Save jsok/4700698 to your computer and use it in GitHub Desktop.
Revisions
-
jsok created this gist
Feb 3, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ # Store the current locale default_loc = locale.getlocale() # Swap to some foreign locale, e.g. German locale.setlocale(locale.LC_ALL, 'de_DE') # Define a new localeconv() with some overrides # see http://docs.python.org/2/library/locale.html#locale.localeconv def _temp_localeconv(lc=locale.localeconv()): lc.update({'decimal_point': ',', 'thousands_sep': '.'}) return lc # Do the override locale.localeconv = _temp_localeconv # Do the actual price string to float conversion using the locale value = locale.atof("1.234,56) # Should return: float 1234.56 # Reset locale locale.setlocale(locale.LC_ALL, default_loc)