Convert Float to Int
To convert integer to float in Python, we can use the int() builtin function. int() builtin function can take a floating-point number and return the integer part of it. Since this is a down casting, any precision (decimal part) would be lost.
In the following program, we will take a floating-point number, and convert it to int.
Python Program
# Take an float
a = 3.14
print('Intput', a, type(a), sep='\n')
# Convert float to integer
output = int(a)
print('\nOutput', output, type(output), sep='\n')
Run Code CopyOutput
Intput
3.14
<class 'float'>
Output
3
<class 'int'>
Summary
In this tutorial of Python Examples, we learned how to convert given value of float datatype to that of int, with the help of well detailed example programs.
Next Topic ⫸ Convert Float to Complex
⫷ Previous Topic Convert Int to String