Méthode Python math.ceil()
Exemple
Arrondissez un nombre vers le haut à son entier le plus proche :
# Import math library
import math
# Round a number upward to its
nearest integer
print(math.ceil(1.4))
print(math.ceil(5.3))
print(math.ceil(-5.3))
print(math.ceil(22.6))
print(math.ceil(10.0))
Définition et utilisation
La math.ceil()
méthode arrondit un nombre à l'entier supérieur le plus proche, si nécessaire, et renvoie le résultat.
Conseil : Pour arrondir un nombre à l'entier inférieur le plus proche, consultez la
math.floor()
méthode.
Syntaxe
math.ceil(x)
Valeurs des paramètres
Parameter | Description |
---|---|
x | Required. Specifies the number to round up |
Détails techniques
Valeur de retour : | Une int valeur, représentant le nombre arrondi. |
---|---|
Journal des modifications : | Python 3+ : renvoie une int valeur Python 2.x : renvoie une float valeur. |