Método Python math.ceil()
Ejemplo
Redondea un número hacia arriba a su entero más cercano:
# 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))
Definición y uso
El math.ceil()
método redondea un número al entero más cercano, si es necesario, y devuelve el resultado.
Sugerencia: Para redondear un número HACIA ABAJO al entero más cercano, observe el
math.floor()
método.
Sintaxis
math.ceil(x)
Valores paramétricos
Parameter | Description |
---|---|
x | Required. Specifies the number to round up |
Detalles técnicos
Valor devuelto: | Un int valor, que representa el número redondeado. |
---|---|
Registro de cambios: | Python 3+: devuelve un int valor Python 2.x: devuelve un float valor. |