SQLite 中的 CEIL 和 FLOOR [英] CEIL and FLOOR in SQLite
问题描述
在 SQLite 中查找数字的 ciel 和 floor 的最简洁方法是什么?不幸的是,SQLite 只有 ROUND()
函数.
What is the cleanest method to find the ciel and floor of a number in SQLite? Unfortunately SQLite only has ROUND()
function.
推荐答案
公式
Ceil : cast ( x as int ) + ( x > cast ( x as int ))
取x的整数部分,如果十进制值大于0则加1
楼层: cast ( x as int ) - ( x
如果十进制值小于0,则取x的整数部分并减1
Formulas
Ceil : cast ( x as int ) + ( x > cast ( x as int ))
Take integer part of x and add 1 if decimal value is greater than 0
Floor : cast ( x as int ) - ( x < cast ( x as int ))
Take integer part of x and subtract 1 if decimal value is less than 0
细胞:SELECT (cast ( amount as int ) + ( amount > cast ( amount as int ))) AS amount从销售地点 id = 128;
楼层:SELECT (cast ( amount as int ) - ( amount
我已经使用 MySQL ceil()
和 floor()
函数检查了所有极端情况,包括负数.
I have checked all the corner cases including negative number with MySQL ceil()
and floor()
functions.
这篇关于SQLite 中的 CEIL 和 FLOOR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!