Python math.ceil - Syntax
mixed ceil(mixed n);
The math.ceil() function in Python is used to return the next highest integer value by rounding up value if necessary.
mixed ceil(mixed n);
mixed n |
Specifies the real number (int, long, float, double) (*Required) |
---|---|
Return int |
Returns an integer respective to an input argument. |
Round the floating point number from 1.0 to 2.0 step by 0.1 using ceiling math method and print the resultant in console.
import math
class MathExample:
def __init__(self):
pass
def getCeilValue(self):
num1 = math.ceil(1.0);
num2 = math.ceil(1.1);
num3 = math.ceil(1.2);
num4 = math.ceil(1.3);
num5 = math.ceil(1.4);
num6 = math.ceil(1.5);
num7 = math.ceil(1.6);
num8 = math.ceil(1.7);
num9 = math.ceil(1.8);
num10 = math.ceil(1.9);
num11 = math.ceil(2.0);
print("The ceiling value of 1.0 is " + str(num1));
print("The ceiling value of 1.1 is " + str(num2));
print("The ceiling value of 1.2 is " + str(num3));
print("The ceiling value of 1.3 is " + str(num4));
print("The ceiling value of 1.4 is " + str(num5));
print("The ceiling value of 1.5 is " + str(num6));
print("The ceiling value of 1.6 is " + str(num7));
print("The ceiling value of 1.7 is " + str(num8));
print("The ceiling value of 1.8 is " + str(num9));
print("The ceiling value of 1.9 is " + str(num10));
print("The ceiling value of 2.0 is " + str(num11));
obj = MathExample()
obj.getCeilValue()
Round the positive floating point number (random numbers) using ceiling math method and print the resultant in console.
import math
class MathExample:
def __init__(self):
pass
def getCeilValue(self):
num1 = math.ceil(1.5698);
num2 = math.ceil(1.3093);
num3 = math.ceil(1.0087);
num4 = math.ceil(1.1038);
num5 = math.ceil(1.9573);
num6 = math.ceil(1.7462);
num7 = math.ceil(1.6427);
num8 = math.ceil(1.4128);
num9 = math.ceil(1.8099);
num10 = math.ceil(1.2743);
num11 = math.ceil(2.0001);
print("The ceiling value of 1.5698 is " + str(num1));
print("The ceiling value of 1.3093 is " + str(num2));
print("The ceiling value of 1.0087 is " + str(num3));
print("The ceiling value of 1.1038 is " + str(num4));
print("The ceiling value of 1.9573 is " + str(num5));
print("The ceiling value of 1.7462 is " + str(num6));
print("The ceiling value of 1.6427 is " + str(num7));
print("The ceiling value of 1.4128 is " + str(num8));
print("The ceiling value of 1.8099 is " + str(num9));
print("The ceiling value of 1.2743 is " + str(num10));
print("The ceiling value of 2.0001 is " + str(num11));
obj = MathExample()
obj.getCeilValue()
Round the negative floating point number (random numbers) using ceiling math method and print the resultant in console.
import math
class MathExample:
def __init__(self):
pass
def getCeilValue(self):
num1 = math.ceil(-1.5698);
num2 = math.ceil(-1.3093);
num3 = math.ceil(-1.0087);
num4 = math.ceil(-1.1038);
num5 = math.ceil(-1.9573);
num6 = math.ceil(-1.7462);
num7 = math.ceil(-1.6427);
num8 = math.ceil(-1.4128);
num9 = math.ceil(-1.8099);
num10 = math.ceil(-1.2743);
num11 = math.ceil(-2.0001);
print("The ceiling value of -1.5698 is " + str(num1));
print("The ceiling value of -1.3093 is " + str(num2));
print("The ceiling value of -1.0087 is " + str(num3));
print("The ceiling value of -1.1038 is " + str(num4));
print("The ceiling value of -1.9573 is " + str(num5));
print("The ceiling value of -1.7462 is " + str(num6));
print("The ceiling value of -1.6427 is " + str(num7));
print("The ceiling value of -1.4128 is " + str(num8));
print("The ceiling value of -1.8099 is " + str(num9));
print("The ceiling value of -1.2743 is " + str(num10));
print("The ceiling value of -2.0001 is " + str(num11));
obj = MathExample()
obj.getCeilValue()
Try to round the infinity using ceiling math method, but it will throw an overflow error.
import math
class MathExample:
def __init__(self):
pass
def getCeilValue(self):
# Positive ∞ infinite value
n = math.ceil(float("inf"))
print("The ceiling value of inf is " + str(n))
# Negative ∞ infinite value
x = math.ceil(-float("inf"))
print("The ceiling value of -inf is " + str(x))
obj = MathExample()
obj.getCeilValue()