Displaying the Integer Part of a Value in Python

udanielnogueira

Daniel Nogueira

Posted on November 5, 2022

Displaying the Integer Part of a Value in Python

We can check the integer part of a real number, and one of the ways to do that is using the trunc() method of the math library.

Let's import the method:

from math import trunc
Enter fullscreen mode Exit fullscreen mode

Then we read a real number and display its truncated value on the screen:

n = float(input('Real number: '))

print(f'Integer part: {trunc(n)}')
Enter fullscreen mode Exit fullscreen mode

Another way is simply using the int() function to display the value in its entirety.

print(f'Integer part: {int(n)}')
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
udanielnogueira
Daniel Nogueira

Posted on November 5, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related