SQLite 中的 CEIL 和 FLOOR [英] CEIL and FLOOR in SQLite

查看:95
本文介绍了SQLite 中的 CEIL 和 FLOOR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQLite 中查找数字的 cielfloor 的最简洁方法是什么?不幸的是,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆