Question

I am aware of what the ceil function does, it rounds numbers up. So; 1.3 to 2.0 and 5.9 to 6.0. But I want it to round up with steps of 0.5. So; 1.3 to 1.5 and 5.9 to 6.0. Is this possible? Thanks!!!

Was it helpful?

Solution

y = ceil(x * 2.0)/2.0;

should do what you need:

x     x*2.0   ceil(x*2.0)  y
------------------------------
1.3    2.6     3.0         1.5
1.6    3.2     4.0         2.0
5.9   11.8    12.0         6.0
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top