Méthode Python math.floor()

Python math 模块Module math de Python

Python math.floor(x)La méthode arrondit x à l'entier inférieur le plus proche.

math.ceil()La méthode arrondit un nombre à l'entier supérieur le plus proche.

Syntaxe

La syntaxe de la méthode math.floor() est la suivante :

math.floor(x)

Description des paramètres :

  • xx -- Obligatoire, un nombre. Si x n'est pas un nombre, renvoie TypeError.

Valeur de retour

Renvoie un entier int représentant le nombre arrondi à l'entier inférieur.

Exemple

L'exemple suivant renvoie le nombre arrondi à l'entier inférieur le plus proche :

Exemple

# Importer le package math
import math

# Affiche le nombre arrondi à l'entier inférieur le plus proche
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))

Sortie :

0
1
5
-6
22
10

Python math 模块Module math de Python

Autres extensions