I want to convert a dollar value to decimal for some simple math.
Following python: how to convert currency to decimal? I have:
def dollars_to_decimals(dollars):
from decimal import Decimal
return Decimal(dollars.strip('$'))
Now when I try:
Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] on win32
my_item['price']
'$24,900'
x = my_item['price']
type(x)
<class 'str'>
dollars_to_decimals(x)
Traceback (most recent call last):
File "C:\PYCHARM\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
File "....\parsing.py", line 26, in dollars_to_decimals
return Decimal(dollars.strip('$'))
decimal.InvalidOperation: [<class 'decimal.ConversionSyntax'>]
What am I doing wrong?