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

1 Answer

0 votes
import math 
 
def roundUpToNearest5(num):
    return math.ceil(num / 5) * 5
     
print(roundUpToNearest5(13))
print(roundUpToNearest5(14))
print(roundUpToNearest5(16))

print(roundUpToNearest5(7))
print(roundUpToNearest5(3))
print(roundUpToNearest5(4))
print(roundUpToNearest5(5))
 
print(roundUpToNearest5(-1))
print(roundUpToNearest5(-9))
 
 
 
 
 
'''
run:
 
15
15
20
10
5
5
5
0
-5

'''

 



answered Jul 17, 2022 by avibootz

Related questions

1 answer 228 views
1 answer 218 views
1 answer 259 views
1 answer 184 views
1 answer 221 views
1 answer 211 views
1 answer 178 views
...