The title of your thread is "How do I round to the nearest hundred", but that's not what you're doing here:
Quote:
Originally Posted by lucmove
Code:
someFunction() {
if (someVar > 2000) {return 2;}
if (someVar > 1900) {return 1.9;}
if (someVar > 1800) {return 1.8;}

You're always rounding
down to the nearest hundred, which is something entirely different.
The pseudocode for doing this, is as follows:
Code:
someVar = someVar / 100 # the significant part is now whatever's left of the decimal point
someVar = int(someVar) # discards decimals
someVar = someVar * 100 # restores correct order of magnitude
The
expr program, which is part of most Linux distributions, doesn't do floatingpoint math at all, so this will actually work:
Code:
~$ expr 1243 / 100 \* 100
1200
~$
Note that the asterisk has to be escaped to prevent
bash from expanding it.
Most programming languages have an
int function, so "someVar = int(someVar/100) * 100" ought to work.
Now that's simply rounding down to the nearest hundred. Since you seem to want the function to return thousands with one decimal place of precision, divide by 10 at the end instead of multiplying by 100. Take care to do so outside the
int function, as you don't want the final result rounded or truncated.