如何将小数点四舍五入到上限值
我正在使用 sql server 2008 过程,我有总行数除以每页,我希望如果结果包含任何小数值,则应四舍五入到其上限值。
我在下面使用:
SELECT FLOOR(@TOTAL / CAST(@PageSize AS FLOAT)) AS TOTALPAGES, @TOTAL AS TOTALROWS
其中@total是浮点数,这不起作用。我也在下面尝试过,
SELECT ROUND(@TOTAL / CAST(@PageSize AS FLOAT),0) AS TOTALPAGES, @TOTAL AS TOTALROWS
这仅在小数> = 5时有效,否则它不取上限值。
我希望如果结果是 12.2 那么它应该返回 13
i am using sql server 2008 procedure, i have total rows divide by per page, i want that if the results contains any decimal value it should be rounded to its upper value.
i used below:
SELECT FLOOR(@TOTAL / CAST(@PageSize AS FLOAT)) AS TOTALPAGES, @TOTAL AS TOTALROWS
where @total is the float, this does not work. i also tried below
SELECT ROUND(@TOTAL / CAST(@PageSize AS FLOAT),0) AS TOTALPAGES, @TOTAL AS TOTALROWS
This works only when the decimal is >= 5, else it does not take the upper value.
i want that if the results is 12.2 then it should return 13
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要使用
CEILING
函数。不是您问题中的ROUND
或FLOOR
。You need to use the
CEILING
function. NotROUND
orFLOOR
as in your question.如果您有任何小数值,则应使用 CELLING 将其四舍五入到其上限值,否则使用 Round 给出准确的值。
希望能解答您的疑惑
If u have any decimal values it should be rounded to its upper value use CELLING or else use Round it give the accurate values.
Hope it will clear your doubts