I have been utilizing the code underneath to conveniently adjust to 1dp where I required the .5s to adjust upwards, for example, I needed a value, for example, 36.25 to adjust to 36.3, not 36.2.
def my_round(n, ndigits=1):
try:
part = n * 10 ** ndigits
delta = part - int(part)
# always round "away from 0"
if delta >= 0.5 or -0.5 < delta <= 0:
part = math.ceil(part)
else:
part = math.floor(part)
val = part/(10 ** ndigits)
except ValueError:
val = np.nan
return val
I currently need to round an alternate decimal column in a df to the closest 5 whole numbers. Would anyone be able to help recommend how I can change my unique code above? I need, for instance, a worth, for example, 702.5000 adjusting to 705. Utilizing the normal Round() it clearly goes to 700. In the model, any remaining ordinary adjusting rules ought to apply for example
702.222 to 700,
707.466 to 705,
703.021 to 705