I need to convert a string to Decimal()
in Python, but it can have the characters "." and "," because of the Brazilian format, it could be something like "80.255,00". I used the string's replace()
method like this str_value = str_value.strip().replace (". "," ").replace (", ",". ")
and then converted it to Decimal like this value = Decimal(str_value)
, but I was wondering if there is a pythonic way of doing this, because using replace twice and then Decimal doesn't seem like the most beautiful way to do this, besides if the string is wrong like "80,255,00", "80,255.00" or "80.255.00" this will not work correctly :( In addition, the value may have more places after the comma, such as "80.255,0045".
Thanks to anyone who helps me