Python math.trunc() Metodo
Esempio
Trova la parte intera di numeri diversi:
# 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))
Definizione e utilizzo
Il math.trunc()
metodo restituisce la parte intera troncata di un numero.
Nota: questo metodo NON arrotonda il numero per eccesso o per difetto al numero intero più vicino, ma rimuove semplicemente i decimali.
Sintassi
math.trunc(x)
Valori dei parametri
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 |
Dettagli tecnici
Valore di ritorno: | Un int valore, che rappresenta le parti intere troncate di un numero |
---|---|
Versione Python: | 1.4 |