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

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

Posted by: admin November 1, 2017 Leave a comment

Questions:

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

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

There you go. Use float (which is almost always a C double).

Questions:
Answers:

The decimal operator might be more in line with what you are looking for:

>>> from decimal import Decimal
>>> x = "234243.434"
>>> print Decimal(x)
234243.434