Python 删除美元金额中的逗号 [英] Python Remove Comma In Dollar Amount

查看:88
本文介绍了Python 删除美元金额中的逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Python v2,我让用户在字符串中输入一个金额,如下所示:

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.

有没有办法去掉输入的逗号?IE: $10,000.00 变成 10000.00

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

感谢您的帮助.

推荐答案

您可以使用 replace 删除所有逗号:

You could use replace to remove all commas:

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

这篇关于Python 删除美元金额中的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆