找到最干净的方法是什么ciel and floor中的一个数SQLite?不幸的是 SQLite 只有ROUND()
功能。
Formulas
Ceil : cast ( x as int ) + ( x > cast ( x as int ))
取x的整数部分,如果小数值大于0则加1
Floor : cast ( x as int ) - ( x < cast ( x as int ))
取 x 的整数部分,如果小数值小于 0,则减 1
Examples
Ceil :
SELECT (cast ( amount as int ) + ( amount > cast ( amount as int ))) AS amount
FROM SALES WHERE id = 128;
Floor :
SELECT (cast ( amount as int ) - ( amount < cast ( amount as int ))) AS amount
FROM SALES WHERE id = 128;
我已经用 MySQL 检查了所有极端情况,包括负数ceil()
and floor()
功能。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)