In this tutorial, we will look at how to convert an integer (int
datatype) in Python to a float (float
datatype) with the help of some examples.
How to convert int to float in Python?

You can use the Python built-in float()
function to convert an integer to a float. Pass the integer you want to convert as an argument. The following is the syntax –
# convert integer i to float float(i)
It returns the number as a float value.
Example
Let’s look at some examples of using the above syntax to convert an integer value to a float.
Here we apply the float()
function on an integer value 12
.
# integer variable num = 12 # convert integer to float num = float(num) # display the number and its type print(num) print(type(num))
Output:
12.0 <class 'float'>
You can see that the variable num
is of float
type now with the value 12.0
.
Alternatively, you can perform an arithmetic identity operation on the integer with a float value to get the resulting value as an integer. For example, multiply or divide the integer by 1.0
or add or subtract 0.0
to get the same value but as a float.
Introductory ⭐
- Harvard University Data Science: Learn R Basics for Data Science
- Standford University Data Science: Introduction to Machine Learning
- UC Davis Data Science: Learn SQL Basics for Data Science
- IBM Data Science: Professional Certificate in Data Science
- IBM Data Analysis: Professional Certificate in Data Analytics
- Google Data Analysis: Professional Certificate in Data Analytics
- IBM Data Science: Professional Certificate in Python Data Science
- IBM Data Engineering Fundamentals: Python Basics for Data Science
Intermediate ⭐⭐⭐
- Harvard University Learning Python for Data Science: Introduction to Data Science with Python
- Harvard University Computer Science Courses: Using Python for Research
- IBM Python Data Science: Visualizing Data with Python
- DeepLearning.AI Data Science and Machine Learning: Deep Learning Specialization
Advanced ⭐⭐⭐⭐⭐
- UC San Diego Data Science: Python for Data Science
- UC San Diego Data Science: Probability and Statistics in Data Science using Python
- Google Data Analysis: Professional Certificate in Advanced Data Analytics
- MIT Statistics and Data Science: Machine Learning with Python - from Linear Models to Deep Learning
- MIT Statistics and Data Science: MicroMasters® Program in Statistics and Data Science
🔎 Find Data Science Programs 👨💻 111,889 already enrolled
Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.
Here’s an example –
# integer variable num = 12 # convert integer to float print(num*1.0) print(num/1.0) print(num+0.0) print(num-0.0)
Output:
12.0 12.0 12.0 12.0
You can see that all the above operations result in the float value 12.0
You might also be interested in –
- Extract Numbers From String in Python
- Python – Check if String Contains Only Numbers
- Python – Convert Integer to String
Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.