Skip to content

Python convert int to float

  • by

Use the float() function to convert int to float in Python. float() builtin function can take an integer as an argument and return a floating-point number with the value as that of the given integer.

float_version = float(int_version)

Python converts int to float example

A simple example code converts an integer to a float in Python.

a = 5
print('Intput', a, type(a), sep='\n')

#convert integer to float
output = float(a)
print('\nOutput', output, type(output), sep='\n')


Python convert int to float

Int to Float using Implicit Conversion

The Implicit conversion is the process where the Python interpreter converts the given int to float when the int is added/subtracted/etc., with a floating-point number.

a = 15

#convert integer to float implicitly
output = a + 0.0

Comment if you have any doubts or suggestions on this Python conversion topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *