Python función floor()

Python 数字Números en Python


Descripción

floor() devuelve el entero redondeado hacia abajo de un número.


Sintaxis

La sintaxis del método floor() es la siguiente:

import math

math.floor( x )

Nota:No se puede acceder a floor() directamente; se debe importar el módulo math y llamar a este método a través del objeto estático.


Parámetros

  • x -- expresión numérica.

Valor de retorno

Devuelve el entero redondeado hacia abajo del número.

Ejemplo

El siguiente ejemplo muestra el uso del método floor():

#!/usr/bin/python
import math   # This will import math module

print "math.floor(-45.17) : ", math.floor(-45.17)
print "math.floor(100.12) : ", math.floor(100.12)
print "math.floor(100.72) : ", math.floor(100.72)
print "math.floor(119L) : ", math.floor(119L)
print "math.floor(math.pi) : ", math.floor(math.pi)

Después de ejecutar el ejemplo anterior, el resultado de salida es:

math.floor(-45.17) :  -46.0
math.floor(100.12) :  100.0
math.floor(100.72) :  100.0
math.floor(119L) :  119.0
math.floor(math.pi) :  3.0

Python 数字Números en Python

Otras extensiones