How do I convert a string to a double in Python?


Question

I would like to know how to convert a string containing digits to a double.

1
186
1/27/2009 10:37:55 AM

>>> x = "2342.34"
>>> float(x)
2342.3400000000001

There you go. Use float (which behaves like and has the same precision as a C,C++, or Java double).

275
1/4/2019 5:45:45 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon