How can i round an (int) so that a number like (22536) is equal to 22000 or 23000?
I haven't found a specific method in the Math class, Math.Round seems to round double only to the nearest int.
By using modulus:
int x = 1500;
int result = x % 1000 >= 500 ? x + 1000 - x % 1000 : x - x % 1000;
It checks if x
has any more than 499 when the thousands are stripped, and then rounds it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With