Convert the string to Double in Python
In this post we will give you information about Convert the string to Double in Python. Hear we will give you detail about Convert the string to Double in PythonAnd how to use it also give you demo for it if it is necessary.
we are going to learn about how to convert the string to a double in Python with the help of examples.
Consider, we have the following string in our code:
str = "234.123"
Now, we need to convert the above string “234.123” to a double 234.123.
Using float() function
To convert a string to a double, we can use the built-in float() function in Python.
The float() function takes the string as an argument and converts it to a double.
Here is an example:
str = "234.123"print(float(str))
Output:
234.123
Similarly, we can use the Decimal() function in Python to convert a string to Double.
Here is an example:
from decimal import Decimalstr = "234.123"result = Decimal(str)print(result)print(type(result))
Output:
234.123<class 'decimal.Decimal'>
Note: In the above code, we have imported the Decimal() function from the decimal module.
Hope this code and post will helped you for implement Convert the string to Double in Python. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs