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

user46646 picture user46646 · Jan 27, 2009 · Viewed 473.4k times · Source

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

Answer

Mongoose picture Mongoose · Jan 27, 2009
>>> 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).