Python is an open-source programming language used by beginners for its easy-to-read code and experts for its substantial libraries and ability to add modules from other programming languages such as C. When programming in Python, you may need to convert an integer or a string to a floating point number, or float. An example is when you need more accuracy in performing a calculation than is provided with the integer data type. Use the float command to convert a number to a floating point format.
Open your Python interpreter.
Video of the Day
Type the following:
numberInt = 123.45678 float (numberInt)
Press "Enter." Python returns:
In this example, Python converts the integer to a floating point numeral. For a numerical string, the code is the same. Consider the string example:
numberEx = '123.45678' float (numberEx)
Python converts the string to the floating point number "123.45677999999999."