在SQL中舍入数字 [英] Rounding NUMBERS IN SQL
本文介绍了在SQL中舍入数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在sql中舍入数字
但有1个条件为小数
例如
声明@x float
选择@ x = 34.44->在这种情况下,我要@ x = 34
选择@ x = 34.6->在这种情况下,我要@ x = 35
选择@ x = 34.5->在这种情况下,我要@ x = 34.5
含义
如果分数小于50%,则像地板函数一样工作
如果分数大于50%,则像天花板函数一样工作
如果分数等于50%,则不执行任何操作
因此,我需要该
i want to round numbers in sql
but there ''s 1 condition with fraction
for example
declare @x float
select @x=34.44 --> in this is case i want @x=34
select @x=34.6 --> in this is case i want @x=35
select @x=34.5--> in this is case i want @x=34.5
meaning
if the fraction is less than 50% then work like floor function
if the fraction is greater thqn 50% then work like ceiling function
if the fraction is equl 50% do nothing
so i need help in that
推荐答案
select (case when @x - floor(@x) < 0.5 then floor(@x) when @x - floor(@x) > 0.5 then ceiling(@x) else @x end)
您是否尝试过(DENOMINATION,2)?
Did you try round(DENOMINATION, 2)?
这篇关于在SQL中舍入数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文