Round to Next .05 in C

前端 未结 5 1281
梦毁少年i
梦毁少年i 2021-01-27 08:44

Consider a float value like 1.82 set by the user. How do I find the next highest .05 value? For the given example the next highest value is 1.85.

Is the

5条回答
  •  北海茫月
    2021-01-27 09:36

    You can use something like

        // Rounds X to the nearest Y
        double round(double x, double y)
        {
            return floor(x / y + 0.5) * y;
        }
    

提交回复
热议问题