Méthode Python math.ceil()
Python math.ceil(x)La méthode arrondit x à l’entier supérieur le plus proche.
math.floor()La méthode arrondit un nombre à l’entier inférieur le plus proche.
Syntaxe
La syntaxe de la méthode math.ceil() est la suivante :
math.ceil(x)
Description des paramètres :
- x-- Requis, un nombre. Si x n'est pas un nombre, renvoie TypeError.
Valeur de retour
Renvoie un entier représentant le nombre arrondi.
Exemple
L'exemple suivant renvoie le nombre arrondi à l'entier le plus proche supérieur :
Exemple
# Importer le package math
import math
# Affiche le nombre arrondi à l'entier le plus proche supérieur
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))
import math
# Affiche le nombre arrondi à l'entier le plus proche supérieur
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))
Résultat de sortie :
2 6 -5 23 10Autres extensions
Module math de Python