Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我知道 ceil 函数的作用,它将数字向上取整。所以; 1.3 到 2.0 和 5.9 到 6.0。但我希望它以 0.5 的步长四舍五入。所以; 1.3 到 1.5 和 5.9 到 6.0。这可能吗?谢谢!!!
y = ceil(x * 2.0)/2.0;
应该做你需要的:
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