Reputation: 668
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!!!
Upvotes: 1
Views: 127
Reputation: 539915
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
Upvotes: 4