programming-examples/python/Math/Round up a number to specified digits.py

12 lines
268 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
import math
def roundup(a, digits=0):
n = 10**-digits
return round(math.ceil(a / n) * n, digits)
x = 123.01247
print("Original Number: ",x)
print(roundup(x, 0))
print(roundup(x, 1))
print(roundup(x, 2))
print(roundup(x, 3))