Metoda Python math.trunc().
Příklad
Najděte celočíselnou část různých čísel:
# 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))
Definice a použití
Metoda math.trunc()
vrací zkrácenou část celého čísla.
Poznámka: Tato metoda NEZAokrouhlí číslo nahoru/dolů na nejbližší celé číslo, ale jednoduše odstraní desetinná místa.
Syntax
math.trunc(x)
Hodnoty parametrů
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 |
Technické údaje
Návratová hodnota: | Hodnota int představující zkrácené části celého čísla |
---|---|
Verze Pythonu: | 1.4 |