Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Remove Comma In Dollar Amount

Tags:

python

string

Using Python v2, I have the user entering an amount into a string as below:

RawPurchaseAmount = raw_input("Please enter purchase amount: ")

PurchaseAmount = float(RawPurchaseAmount.strip().lstrip("$"))

This is stripping out any blank spaces at the front of the input, and removing the $ sign if one is entered.

Is there a way to remove a comma symbol if it is entered? IE: $10,000.00 to become 10000.00

Thanks for any help.

like image 830
The Woo Avatar asked Mar 03 '11 11:03

The Woo


1 Answers

You could use replace to remove all commas:

"10,000.00".replace(",", "")

like image 128
NPE Avatar answered Oct 21 '22 22:10

NPE