Skip to content

How to Convert String to Double in Python

If you need to convert a String to a Double in your Python code:

Option 1 – Convert String to Double using float()

string = '1234.5678' myfloat = float(string) print(myfloat)
Code language: Python (python)

Option 2 – Convert String to Double using decimal.Decimal()

from decimal import Decimal string = '1234.5678' myfloat = Decimal(string) print(myfloat)
Code language: Python (python)

See also  Find the Maximum Length Difference between Lists/Arrays in Python
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x