Skip to main content
 首页 » 编程设计

python之使用 atof 转换数字

2024年09月07日7emanlee

<分区>

在 Python 3.5 中,我想使用带有以下代码的 locale.atof 将德语数字字符串转换为 float :


import locale 
from locale import atof 
locale.setlocale(locale.LC_ALL, 'de_DE') 
 
number = atof('17.907,08') 

然而,这引发了一个ValueError:

ValueError: could not convert string to float: '17.907.08' 


为什么?这不正是 atof() 的用途吗?