素材牛VIP会员
转换一个字符串为浮点数会报错 float('‐525050.87')
 ed***on  分类:Python  人气:828  回帖:2  发布于6年前 收藏

float('‐525050.87')

ValueError: could not convert string to float: ‐525050.87

 标签:python

讨论这个帖子(2)垃圾回帖将一律封号处理……

Lv5 码农
麦***j 产品经理 6年前#1

在我回答你之前, 讓我先問個更奇怪的問題先:

In [60]: '‐' == '-'
Out[60]: False

WHY ?????

讓我來告訴你為什麼, 這就是真相:

en dash

重點在這裡:

An en dash or en rule (–) is wider than a hyphen (-) and narrower than an em dash (–).

舉一要能反三, 我再問個問題:

>>> float('-553l.4')
ValueError: could not convert string to float: '-553l.4'

這題比較簡單, 相信你也知道原因了...


我回答過的問題: Python-QA

Lv3 码奴
上***水 职业无 6年前#2

预计是将半角的"-"输错为全角了

 文明上网,理性发言!   😉 阿里云幸运券,戳我领取