Python 不规则字符串转换为数字的操作?

对接第三方 API 时候返回:1,84784375793845 这样的东西让人无语但是这接口几万年前的了不可能让人改了,于是我尝试 int() float() 都挂了:

ValueError: invalid literal for int() with base 10: '1,1690424803471498470'
ValueError: could not convert string to float: '1,1690424803471498470'

请问有什么好的办法么?

阅读 1.9k
1 个回答
num_str = "1,1690424803471498470"
clean_num_str = num_str.replace(",", "")
num = float(clean_num_str)
num

输出:

1.16904248034715e+19
推荐问题