在 SQLite 中获取数字的 ceil 值 [英] Getting the ceil value of a number in SQLite

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

问题描述

所以我看到这个问题有一个很好的答案,但无论如何我都想四舍五入,而不是无论如何都要四舍五入.例如,在转换 int 之前向其添加 1 将不起作用,因为它会将 5.0四舍五入"为 6.0.

So I see this question has a good answer, but I want to round up no matter what, instead of rounding down no matter what. Adding 1 to it before casting int wouldn't work because it would "round" 5.0 into 6.0, for example.

那么我应该如何在 SQLite 中实现 ceil ?

So how should I implement ceil in SQLite?

推荐答案

这个怎么样?

select (case when x = cast(x as int) then cast(x as int)
             else 1 + cast(x as int)
        end)

这篇关于在 SQLite 中获取数字的 ceil 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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