I need to convert a string currency string in Continental Europe format into a float number:
Input:
\'6.150.593,22 €\'
Realize tha
A simple solution may be as follows:
>>> val = '6.150.593,22 €'
>>> res = val[:-2].split(',')
>>> float('.'.join([res[0].replace('.', ''), res[1]]))
6150593.22
value = '6.150.593,22 €'
value = value.split()[0] #Take out euro symbol
integer, decimal = value.split(',') #Separate integer and decimals
integer = integer.replace('.','') #Take out dots
final_value = int(integer) + (int(decimal) * (10**(-len(decimal))))
Use locale.atof
https://docs.python.org/3/library/locale.html#locale.atof
>>> import locale
>>> locale.setlocale(locale.LC_NUMERIC,"nl")
'nl'
>>> locale.atof("6.150.593,22")
6150593.22
A good way of doing it (1 line) :
NewValue = float(value[:-2].replace(".", "").replace(",","."))