How to Convert Float to Integer Type Value in Python

In this tutorial, Learn how to convert float to integer type value in Python. The short answer is: use int() function to convert a positive or negative float value to an integer.

If you use only the int(), you will get integer value without a round figure. To convert float to int with the round figure, read this tutorial to the end.

Python Convert Float to Integer Using int()

If you want to convert float to integer variable type in Python. You have to use the int() function of Python. Pass the float variable as the argument of the int() function in Python.

To print the resulted integer value after conversion, you have to use the Python print function.

Output

10

The above example prints the integer value in the output. However, this is the positive conversion of the positive float value. If you want to convert a negative float value to an integer, you have to read the next section of this post.

How to Change Negative Float Value to Int in Python

To convert the negative float value, you have to use the same int() function. You have to also pass the float variable as the argument of the int() in Python.

The negative float value gives the negative integer on conversion.

Output

-10

The above example showing the negative integer value in the output after conversion. All the above example showing the conversion from float to int without round figure.

If you want to convert float to integer type value with round figure conversion. Read the next section of the post to learn how to how to make the conversion with round figure.

How to Altering Float to Int in Round Figure

If you want to convert float to int type value in Python with a round figure. You have to use the round() function of Python inside the int() function. Pass the float variable as the argument of the round() function in Python.

The round() function add one to the integer value after conversion, if the digit after the decimal point is more than 5.

Output

11

The above example contains 10 as the float value before the decimal point. However, the resulted integer value after conversion gives 11 as the output. This is just because the float contains the value of more than 5 after the decimal point.

You may also like to read

Hope, you like this tutorial of how to convert float to an integer value in Python. If you have any query regarding the tutorial, please comment below.

References

Also tell me, which method you are using to convert the float type value to int type.

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.