How to round a number down to the nearest 500 in Python

1 Answer

0 votes
import math 
  
def roundDownToNearest500(num):
    return math.floor(num / 500) * 500

print(roundDownToNearest500(3)) 

print(roundDownToNearest500(49)) 

print(roundDownToNearest500(550))  
print(roundDownToNearest500(450)) 
print(roundDownToNearest500(500))

print(roundDownToNearest500(751))

print(roundDownToNearest500(1300))

print(roundDownToNearest500(-1))
print(roundDownToNearest500(-10))
print(roundDownToNearest500(-700))





'''
run:

0
0
500
0
500
500
1000
-500
-500
-1000

'''

 



answered Jul 18, 2022 by avibootz

Related questions

1 answer 121 views
1 answer 117 views
1 answer 108 views
1 answer 115 views
1 answer 106 views
1 answer 121 views
...