如何将带有浮点数的字符串转换为另一种数据类型?

how to convert a string with floats numbers to another data type?

字符串将是某些产品的价格,所以它基本上会像这样 '1,433.10',问题是我需要将它与用户输入的值进行比较输入整数是因为 isdigit() 方法,用于检查输入是否为数字,这会导致比较失败。 我已经尝试过转换为 int、float,但没有任何效果,它只产生异常

def convert_values():
        price = results['price'][2:] # here is where the string with the value is, which in this case is '1,643.10'
        print(int(float(price))) # if I try to cast just to int: ValueError: invalid literal for int() with base 10: '1,643.10'

转换前,将字符串中的逗号替换为''为:

price = results['price'][2:].replace(',', '')
print(int(float(price)))