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

1 Answer

0 votes
import math 

def roundUpToNearest100(num):
    return math.ceil(num / 100) * 100
    
print(roundUpToNearest100(138))

print(roundUpToNearest100(238))

print(roundUpToNearest100(349))
print(roundUpToNearest100(350))
print(roundUpToNearest100(351))

print(roundUpToNearest100(-101))
print(roundUpToNearest100(-109))





'''
run:

200
300
400
400
400
-100
-100

'''

 



answered Jul 16, 2022 by avibootz

Related questions

1 answer 107 views
1 answer 112 views
1 answer 110 views
1 answer 125 views
1 answer 107 views
...