在目标C中将浮点数舍入为1/4

Chr*_*isB 2 math floating-point objective-c

将一个浮点数舍入到目标C中最接近1/4的最优雅的方法是什么?

例如:

3.14 should be 3.25
2.72 should be 2.75
6.62 should be 6.50
1.99 should be 2.00
Run Code Online (Sandbox Code Playgroud)

等等

ken*_*ytm 5

#include <math.h>
...

newValue = round (value * 4.0) / 4.0;
Run Code Online (Sandbox Code Playgroud)