Python Convert Float to Int

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

Output

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.