Python Remove Comma In Dollar Amount

前端 未结 4 1443
失恋的感觉
失恋的感觉 2020-12-05 19:27

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

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

PurchaseAmount         


        
4条回答
  •  再見小時候
    2020-12-05 20:30

    >>> x = '$10,00.00'
    >>> ''.join(e for e in x if e.isdigit() or e == '.')
    '1000.00'
    

    Remove the $, any other character, except a digit or a . in one go.

提交回复
热议问题