Author -  Sai gowtham

How to convert the float to Int in Python

In this tutorial, we will learn about how to convert the float to an Int in Python with the help of examples.

Using int() method

To convert a float value to an Int, we can use the built-in int() method in Python.

The int() method takes the float value as an argument and converts it to integer.

Here is an example:

afloat = 12.79
result = int(afloat)

print(result)

Output:

12

Note: When we use the int() constructor the Integer is always rounded to the nearest downward value, like 12.752 to 12 or 6.99 to 6.

Using trunc() method

Similarly, we can also use the built-in trunc() method in python to convert a float to int.

The trunc() method takes the float value as an argument and returns the integer part of it by stripping the decimal values.

Here is an example:

from math import trunc

afloat = 12.79
result = trunc(afloat)

print(result)

Output:

12

Note: We have imported the trunc() method from the python math module

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY