Método Python math.trunc()
Ejemplo
Encuentra la parte entera de diferentes números:
# Import math Library
import math
# Return the truncated integer
parts of
different numbers
print(math.trunc(2.77))
print(math.trunc(8.32))
print(math.trunc(-99.29))
Definición y uso
El math.trunc()
método devuelve la parte entera truncada de un número.
Nota: Este método NO redondeará el número hacia arriba o hacia abajo al entero más cercano, sino que simplemente eliminará los decimales.
Sintaxis
math.trunc(x)
Valores paramétricos
Parameter | Description |
---|---|
x | Required. The number you want to remove the decimal part of. If the value is not a number, it returns a TypeError |
Detalles técnicos
Valor devuelto: | Un int valor, que representa las partes enteras truncadas de un número |
---|---|
Versión de Python: | 1.4 |