Metoden ceil i math-modulen

Metoden ceil i modulen math avrundar tal till heltal alltid uppåt.

Syntax

pythonimport math

math.ceil(tal)

Exempel

Låt oss avrunda talet 25.38 uppåt:

pythonimport math

print(math.ceil(25.38))

Resultat av kodkörning:

python26

Exempel

Låt oss nu använda metoden ceil på talet -4.88:

pythonimport math

print(math.ceil(-5.25))

Resultat av kodkörning:

python-5

Se även

  • funktionen round,
    som avrundar tal
  • metoden floor i modulen math,
    som avrundar tal nedåt