Python math.floor()-Methode
Python math.floor(x)Die Methode rundet x auf die nächste ganze Zahl ab.
math.ceil()Die Methode rundet eine Zahl auf die nächste ganze Zahl auf.
Syntax
Die Syntax der math.floor()-Methode lautet wie folgt:
math.floor(x)
Parameterbeschreibung:
- xx -- Erforderlich, eine Zahl. Wenn x keine Zahl ist, wird TypeError zurückgegeben.
Rückgabewert
Gibt eine ganze Zahl int zurück, die die abgerundete Zahl darstellt.
Beispiel
Das folgende Beispiel gibt die auf die nächste ganze Zahl abgerundete Zahl zurück:
Beispiel
# Importiere das math-Paket
import math
# Gibt die auf die nächste ganze Zahl abgerundete Zahl aus
print(math.floor(0.6))
print(math.floor(1.4))
print(math.floor(5.3))
print(math.floor(-5.3))
print(math.floor(22.6))
print(math.floor(10.0))
import math
# Gibt die auf die nächste ganze Zahl abgerundete Zahl aus
print(math.floor(0.6))
print(math.floor(1.4))
print(math.floor(5.3))
print(math.floor(-5.3))
print(math.floor(22.6))
print(math.floor(10.0))
Ausgabe:
0 1 5 -6 22 10Andere Erweiterungen
Python math-Modul