![](/img/trans.png)
[英]Number to string conversion with f-string without leading or trailing zeros?
[英]Convert string to float without leading and trailing zeros
我收到字符串格式的数据:
input1 = ",1"
input2 = "1,"
我需要将它转换成浮点数并在我的测试中验证它。 我期待这种转换:
",1" -> 0.1
"1," -> 1.0
不使用正则表达式可能吗?
您可以将,
替换为.
使用replace()
然后转换为float
float(input1.replace(',','.'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.