python convert currency to float code example
Example 1: convert price to float python
from re import sub
from decimal import Decimal
money = '$6,150,593.22'
value = Decimal(sub(r'[^\d.]', '', money))
Example 2: python format float as currency
formatted_float = "${:,.2f}".format(1500.2) # Format `1500.2` as currency (note the comma)
print(formatted_float)
# Result: $1,500.20