4

I have a string in the format 100.000,53 (my country uses points as thousands separator and a comma as the decimal separator). I know about:

import locale
locale.setlocale(locale.LC_NUMERIC, 'de_DE')
locale.atof('100.000,53')

However, this seems to always throw ValueError: could not convert string to float: '100.000.53'for me (Python 3.6).

Additionally, as money is involved, I want the result to be a decimals number. Can I simply cast the result of atof to decimal?

psaniko
  • 1,180
  • 16
  • 17

0 Answers0