I know about math.ceil and numpy.ceil, but both of them lack of significance
parameter.
For example in Excel:
=Ceiling(210.63, 0.05)
-> 210.65
numpy.ceil and math.ceil in other hand:
numpy.ceil(210.63)
-> 211.0
math.ceil(210.63)
-> 211.0
So, I wonder, Is there some similar to Excel's solution already?
The ceil() Function:The method ceil(x) in Python returns a ceiling value of x i.e., the smallest integer greater than or equal to x. Syntax: import math math.ceil(x) Parameter: x:This is a numeric expression. Returns: Smallest integer not less than x.
Understanding Python Ceiling()The ceil() function is part of the built-in math module and takes a single argument, a number. The function returns a single number, an integer, that is the smallest integer greater than or equal to the number passed into the argument.
The Excel CEILING function[1] is categorized under Math and Trigonometry functions. The function will return a number that is rounded up to a supplied number that is away from zero to the nearest multiple of a given number. MS Excel 2016 handles both positive and negative arguments.
I don't know of any python function to do so, but you can easily code one :
import math
def ceil(x, s):
return s * math.ceil(float(x)/s)
The conversion to float is necessary in python 2 to avoid the integer division if both arguments are integers. You can also use from __future__ import division
. This is not needed with python 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With