Python math.ceil() Metodo
Esempio
Arrotonda un numero per eccesso al suo intero più vicino:
# 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))
Definizione e utilizzo
Il math.ceil()
metodo arrotonda un numero per UP all'intero più vicino, se necessario, e restituisce il risultato.
Suggerimento: per arrotondare un numero per GIÙ al numero intero più vicino, osserva il
math.floor()
metodo.
Sintassi
math.ceil(x)
Valori dei parametri
Parameter | Description |
---|---|
x | Required. Specifies the number to round up |
Dettagli tecnici
Valore di ritorno: | Un int valore, che rappresenta il numero arrotondato. |
---|---|
Registro modifiche: | Python 3+: restituisce un int valore Python 2.x: restituisce un float valore. |