Problem with ceil function in math module

Viewed 141

by performing the following calculation

p=math.ceil(57050*1.12)

I am receiving 63897. However other tools (such as Excel) deliver 63896.

I need to use ceil (round up), because the procedure is part of a larger model, where I cannot make an exeption this specific value (57050). The problem is that I need to import a current model from Excel into Python and it is very important that all calculations deliver the same values.

I was wondering if there is a way to adjust the precision of "ceil" by e.g. 10 decimals. How can I adjust it, or what else can I do, that is not so severe, so that it is not going to create problems for other values?

Expected results: 63896

Actual results: 63897

1 Answers

Essentially, if you want to make only the first 10 decimal places relevant, you could do something like the following:

def ceil(n):
    return math.ceil(int(n*10**10)/10**10)
Related