Python - Methode math.floor()
Beispiel
Zahlen auf die nächste Ganzzahl abrunden:
# Import math library
import math
# Round numbers down to the
nearest integer
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))
Definition und Verwendung
Die math.floor()
Methode rundet eine Zahl gegebenenfalls auf die nächste Ganzzahl AB und gibt das Ergebnis zurück.
Tipp: Um eine Zahl auf die nächste ganze Zahl aufzurunden, sehen Sie sich die Methode an.
math.ceil()
Syntax
math.floor(x)
Parameterwerte
Parameter | Description |
---|---|
x | Required. Specifies the number to round down |
Technische Details
Rückgabewert: | Ein int Wert, der die gerundete Zahl darstellt |
---|---|
Änderungsprotokoll: | Python 3+ : Gibt einen int Wert zurück Python 2.x : Gibt einen float Wert zurück |