Public
Snippet $150 authored by irul

Excel round in python

sn_excel_round.py
def excel_round(num, decimals=0):
    """https://stackoverflow.com/a/78608344"""
    multiplier = 10**decimals
    if num >= 0:
        return int(num * multiplier + 0.5) / multiplier
    return int(num * multiplier - 0.5) / multiplier

num = 2.5
print(excel_round(num))

# output: 3.0