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个回答

test
2024-06-30
num_str = "1,1690424803471498470"
clean_num_str = num_str.replace(",", "")
num = float(clean_num_str)
num
输出:
1.16904248034715e+19
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容