简体   繁体   English

如何将数字舍入到下一个半整数?

[英]How can I round up numbers to the next half-integer?

In Python floor() and ceil() round to the next higher or lower integer. 在Python floor()ceil()舍入到下一个更高或更低的整数。

How to round up any value between 1.01 - 1.5 to 1.5 and 1.51 - 2.0 to 2.0 etc.? 如何将1.01 - 1.5到1.5和1.51 - 2.0到2.0等之间的任何值四舍五入?

乘以2, ceil() ,除以2:

0.5 * ceil(2.0 * x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM