In Python, I have an array with float numbers expressed as strings with multiple locales.
E.g.:
str_array = ['1,234.56', '7.890,12', '123 456,789']
I would like to convert all of them to float, and append to a new array.
float_array = [1234.56, 7890.12, 123456.789]
I was wondering whether there’s a concise and elegant way to have the job done in Python. I tried something with the locale
module:
<code>import locale
locale.setlocale(locale.LC_NUMERIC, locale='en_EN')
num_string = '1,234.56'
float_num = locale.atof(num_string)
# It prints 1234.56
print(float_num)
</code>
<code>import locale
locale.setlocale(locale.LC_NUMERIC, locale='en_EN')
num_string = '1,234.56'
float_num = locale.atof(num_string)
# It prints 1234.56
print(float_num)
</code>
import locale
locale.setlocale(locale.LC_NUMERIC, locale='en_EN')
num_string = '1,234.56'
float_num = locale.atof(num_string)
# It prints 1234.56
print(float_num)
But I’m searching for a smart way all of the different locales that can appear inside my input array (potentially, any locale on earth). Can anyone help me?
Thank you!