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

1 Answer

0 votes
import math 
 
def roundUpToNearest1000(num):
    return math.ceil(num / 1000) * 1000
    
print(roundUpToNearest1000(1438))
 
print(roundUpToNearest1000(2538))
print(roundUpToNearest1000(2438))

print(roundUpToNearest1000(3499))
print(roundUpToNearest1000(3500))
print(roundUpToNearest1000(3501))

print(roundUpToNearest1000(-3899))

print(roundUpToNearest1000(-3499))
print(roundUpToNearest1000(-3500))
print(roundUpToNearest1000(-3501))
 
 
 
 
 
'''
run:
 
2000
3000
3000
4000
4000
4000
-3000
-3000
-3000
-3000
 
'''

 



answered Jul 16, 2022 by avibootz

Related questions

1 answer 226 views
1 answer 182 views
1 answer 220 views
1 answer 210 views
1 answer 196 views
1 answer 219 views
...