So I am trying to build a frontend where I assume that users will expect "school rounding", as in rounding up from values >= 5. I am however having difficulties getting a consistent solution that works for an arbitrary number of decimals.
I have looked at a few answers, such as this one, but none of them seemed to provide the solution that I needed.
Take this example:
Num = 33.497536945812804
from decimal import Decimal, getcontext, ROUND_HALF_UP
getcontext().rounding=ROUND_HALF_UP
# doesn't work:
round(Decimal(str(Num)))
>>> 33
# if I round to 1 decimal and round again, it works.
round(Decimal(str(round(Decimal(str(Num)), 1))))
>>> 34
Now I suppose I could write a function that works like what you learn at school, i.e. starts with the last digit and works its way to the decimal point, but that seems awfully inefficient and complicated. Is there really no better way or package for achieving this seemingly trivial outcome?