将字符串转换为浮点数,使其在Python'0,3638412'

问题描述 投票:0回答:1

我正在尝试将字符串转换为浮点数

具有浮点功能:

pointsx = float(x)

得到错误:ValueError:无法将字符串转换为浮点型:'0,3638412'

关于如何解决此问题的任何想法?

enter image description here

python string floating-point voronoi
1个回答
1
投票

这应该起作用:

pointsx = float(x.replace( ',', '.'))

浮点数使用点.作为分隔符,而不是逗号。

© www.soinside.com 2019 - 2024. All rights reserved.