Custom locale configuration for float conversion
问题 I need to convert a string in the format "1.234.345,00" to the float value 1234345.00 . One way is to use repeated str.replace : x = "1.234.345,00" res = float(x.replace('.', '').replace(',', '.')) print(res, type(res)) 1234345.0 <class 'float'> However, this appears manual and non-generalised. This heavily upvoted answer suggests using the locale library. But my default locale doesn't have the same conventions as my input string. I then discovered a way to extract the characters used in