I'm dealing with the value of inputs.The input should be rounded down to nearest hundred. For example, if the input is 5398 euros, the input is determined using value 5300 euros.
Asked
Active
Viewed 1,435 times
1
-
2`100*int(5398/100)` should do just that... – hiro protagonist Oct 13 '20 at 12:12
-
Does this answer your question? [Python round up integer to next hundred](https://stackoverflow.com/questions/8866046/python-round-up-integer-to-next-hundred) – Sergey Shubin Oct 13 '20 at 12:12
2 Answers
1
You can do that by taking the integer part of the number divided by 100 and then multiplying by 100:
rounded = int(your_number / 100) * 100

Jerzy Pawlikowski
- 1,751
- 19
- 21
1
You may use either of these three ways (there may exist many more ways):
import math
print(math.floor(5398 / 100.00) * 100)
Output is 5300
as expected.
rounded = int(5398 / 100) * 100
print(rounded)
Still the output is 5300
.
import numpy
print(int(numpy.floor(5398 / 100.0) * 100))
The output is still 5300
:)
Have Fun :)

Saeed
- 3,255
- 4
- 17
- 36
-
no need to use `numpy` for `floor`. that is in [`math.floor`](https://docs.python.org/3/library/math.html#math.floor) already. – hiro protagonist Oct 13 '20 at 15:23