How to round a number up to the nearest 10 in Python

1 Answer

0 votes
import math
 
def roundUpToNearest10(num) :
    return math.ceil(num / 10) * 10
 
print(roundUpToNearest10(33))
print(roundUpToNearest10(59))
print(roundUpToNearest10(599.99))
print(roundUpToNearest10(3.14))
print(roundUpToNearest10(2))
print(roundUpToNearest10(19))
print(roundUpToNearest10(-12))
print(roundUpToNearest10(-101))
print(roundUpToNearest10(-109))
 
 
 
 
'''
run:
 
40
60
600
10
10
20
-10
-100
-100
 
'''

 



answered Jun 10, 2022 by avibootz

Related questions

1 answer 122 views
1 answer 124 views
1 answer 112 views
1 answer 129 views
1 answer 110 views
1 answer 97 views
1 answer 115 views
...