Q:

Is there an easy way in C++ to round to the nearest 1.75 increment

I tried looking up this on StackOverflow, close this question if this has been answered already. But is there a function in C++ that can round a value to an increment with a decimal value? Please generalize your answer for any given decimal increment - I would like to also know, for example, how to round to the nearest 1.78 increment.

A:

There is no specific function to do that, but you can easily make one.  Just divide the value by 1.75, then call std::round and then multiply by 1.75.
e.g.
double round_to_multiple(double val, double step)
{
    return step * std::round(val / step);
}

Where "step" is the step-size, or multiple.  In your case, 1.75.
Just be wary of floating-point rounding error.  If you are always dealing with 2 decimal places and the numbers you work with are in a useful range, you might want to consider using integers instead (multiplied by 100), which would change the technique a little.

