[Tutor] ValueError: could not convert string to float: '13,2'
emile
emile at fenx.com
Fri Jan 3 17:53:41 CET 2014
On 12/31/2013 12:56 PM, Mark Lawrence wrote:
> import locale
>
> # Set to users preferred locale:
> locale.setlocale(locale.LC_ALL, '')
> # Or a specific locale:
> locale.setlocale(locale.LC_NUMERIC, "en_DK.UTF-8")
> print(locale.atof("3,14"))
This is a good solution, but be aware that it could impact other parts
of your porgram as well, particularly if this is a read in data set from
a non-local region. Also, in places where commas are used as decimal
points, it's also common to use periods as commas:
>>> print(locale.atof("123.456,14"))
123456.14
Emile
More information about the Tutor
mailing list