I'm developing a software that has to round value to 50 or 100. In other words, the only allowed values are 0, 50, 100, 150, 200, 250, ...
I want to round a value in this way: if the value is 25 it rounds to 50, but if it is 24, it rounds to 0. The same with 75 rounds to 100, and 74 rounds to 50. And so on.
In other words, [0, 25), rounds to 0. [25, 50], it rounds to 50.
Given $x$ as the input value, I'm using this calculations:
- $x= x/100.0$
- Then, I rounds $x$ towards zero, truncating the fractional part (sorry, I don't know if there is a mathematical symbol for Truncate).
- $x=x*100.0$
- $x=x+50.0$
With these calculations, when $x=804.072$ it returns $850.0$, but it should returns $800.0$.
How can I fix this error?