Python Question

python: how to convert currency to decimal?

i have dollars in a string variable

dollars = '$5.99'

how do i convert this to a decimal instead of a string so that i can do operations with it like adding dollars to it?

Answer Source

There's an easy approach:

dollar_dec = float(dollars[1:])