Excel-like ceiling function in python?

I know about math.ceil and numpy.ceil , but both of them have no significance parameter. For example, in Excel:

=Ceiling(210.63, 0.05) β†’ 210.65

numpy.ceil and math.ceil in the other hand:

numpy.ceil(210.63) β†’ 211.0

math.ceil(210.63) β†’ 211.0

So, I wonder if there are already similar Excel solutions?

+7
source share
2 answers

I don't know any python function, but you can easily code it:

 import math def ceil(x, s): return s * math.ceil(float(x)/s) 

Converting to float is necessary in python 2 to avoid integer division if both arguments are integers. You can also use from __future__ import division . This is not needed with python 3.

+9
source

What you can do is.

 ceil = lambda x,y: math.ceil(x*(1.0/y))/(1.0/y) 

But it is not reliable.

0
source

All Articles