DEV Community

Cover image for Exibindo a Porção Inteira de um Valor em Python
Daniel Nogueira
Daniel Nogueira

Posted on • Edited on

6

Exibindo a Porção Inteira de um Valor em Python

Podemos verificar a parte inteira de um número real, uma das maneiras é usar o método trunc() que existe na biblioteca math.

Para isso, vamos importar o método:

from math import trunc
Enter fullscreen mode Exit fullscreen mode

Em seguida, lemos um número real e exibimos na tela seu valor truncado, ou seja, sua parte inteira:

n = float(input('Número real: '))

print(f'Parte inteira: {trunc(n)}')
Enter fullscreen mode Exit fullscreen mode

Uma outra forma é, simplesmente, usar a função int() para exibir o valor em sua forma inteira.

print(f'Parte inteira: {int(n)}')
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay