首页 > 解决方案 > 如何将₹22000字符串转换为python中的浮点数

问题描述

回溯(最近一次调用):文件“scrap.py”,第 13 行,在 convert_price=float(price[:5]) 中 ValueError:无法将字符串转换为浮点数:'₹\xa022,'

标签: python

解决方案


你可以使用

dirty = "₹22000.83"

try:
    cleaned = float("".join(char for char in dirty if
                            char in ["-", "."] or char.isdigit()))
    print(cleaned)
except ValueError:
    pass

哪个产量

22000.83

推荐阅读