How can I change a string into a floating-point number in Python?

2026-05-28 19:482阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计161个文字,预计阅读时间需要1分钟。

How can I change a string into a floating-point number in Python?

日期:2018.5.30引用:[Stack Overflow](https://stackoverflow.com/questions/482410/how-do-i-convert-a-string-to-a-double-in-python)方法1:pi=3.1415926 float(pi)方法2:from decimal import Decimal x=Decimal(234243.434)


Date: 2018.5.30


Reference:

​​stackoverflow.com/questions/482410/how-do-i-convert-a-string-to-a-double-in-python​​

Method1:



pi = ‘3.1415926’
float(pi)
3.1415926



Method2:



from decimal import Decimal
x = “234243.434”
print Decimal(x)
234243.434





How can I change a string into a floating-point number in Python?


本文共计161个文字,预计阅读时间需要1分钟。

How can I change a string into a floating-point number in Python?

日期:2018.5.30引用:[Stack Overflow](https://stackoverflow.com/questions/482410/how-do-i-convert-a-string-to-a-double-in-python)方法1:pi=3.1415926 float(pi)方法2:from decimal import Decimal x=Decimal(234243.434)


Date: 2018.5.30


Reference:

​​stackoverflow.com/questions/482410/how-do-i-convert-a-string-to-a-double-in-python​​

Method1:



pi = ‘3.1415926’
float(pi)
3.1415926



Method2:



from decimal import Decimal
x = “234243.434”
print Decimal(x)
234243.434





How can I change a string into a floating-point number in Python?