I'd like to round integers down to their nearest 1000 in Java.
So for example:
- 13,623 rounds to 13,000
- 18,999 rounds to 18,000
- etc
I'd like to round integers down to their nearest 1000 in Java.
So for example:
Simply divide by 1000 to lose the digits that are not interesting to you, and multiply by 1000:
i = i/1000 * 1000
Or, you can also try:
i = i - (i % 1000)
You could divide the number by 1000, apply Math.floor
, multiply by 1000 and cast back to integer.