用户登录
用户注册

分享至

如何在 Python 中将带点和逗号的字符串转换为浮点数

  • 作者: 铞侕锒铛龙
  • 来源: 51数据库
  • 2022-12-23

问题描述

如何在 Python 中将像 123,456.908 这样的字符串转换为浮点 123456.908?

How can I convert a string like 123,456.908 to float 123456.908 in Python?

推荐答案

只需用 replace() 去掉 ,:

float("123,456.908".replace(',',''))
软件
前端设计
程序设计
Java相关