四舍五入 字段dj(decimal)的公式(convert(decimal(18,4),case when ([sl] = 0) then 0 else ([total] / [sl]) end)显示出来的数据是小数点后四位,用的是去位法,我想实现小数点后4位四舍五入,怎么改 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 round(case when ([sl] = 0) then 0 else ([total] / [sl]) end,4) select convert(dec(9,4),0.00005)/*---------------------------------------0.0001(1 行受影响)*/楼主那个也能四舍五入。 ROUND返回一个舍入到指定长度或精度的数字表达式。ROUND ( numeric_expression, length [ , function ] ) ROUND返回数字表达式并四舍五入为指定的长度或精度。语法ROUND ( numeric_expression , length [ , function ] ) 参数numeric_expression精确数字或近似数字数据类型类别的表达式(bit 数据类型除外)。length是 numeric_expression 将要四舍五入的精度。length 必须是 tinyint、smallint 或int。当 length 为正数时,numeric_expression 四舍五入为 length 所指定的小数位数。当 length 为负数时,numeric_expression 则按 length 所指定的在小数点的左边四舍五入。function是要执行的操作类型。function 必须是 tinyint、smallint 或 int。如果省略 function 或 function 的值为 0(默认),numeric_expression 将四舍五入。当指定 0 以外的值时,将截断 numeric_expression。返回类型返回与 numeric_expression 相同的类型。SELECT ROUND(123.9994, 3), ROUND(123.9995, 3) GO下面是结果集:----------- -----------123.9990 124.0000 用ROUND 应该可以的 --方法1: select convert(numeric(9,4),0.00005) 结果: 0.0001--方法2: Select round(0.00005,4) 结果: 0.00010 SQLSERVER 2008中取出的中文字符是乱码 T-SQL对字符串的操作 查询 如何知道某个用户访问SQL服务器的情况? 对pdf文件的存储方案 如何同时执行两个不同服务器上的数据库 如何查询表中的重复字段 按“分数”排序,等级分别为:10%优,20%良,60%合格,10%不合格。如何把等级存到“等级”一列? 查询年与年之间的月份差. 求助一个SQL语句:替换某个字段的部分内容。 SQL基础问题 xml sql查询
/*
---------------------------------------
0.0001(1 行受影响)
*/
楼主那个也能四舍五入。
返回一个舍入到指定长度或精度的数字表达式。ROUND ( numeric_expression, length [ , function ] )
返回数字表达式并四舍五入为指定的长度或精度。语法
ROUND ( numeric_expression , length [ , function ] ) 参数
numeric_expression精确数字或近似数字数据类型类别的表达式(bit 数据类型除外)。length是 numeric_expression 将要四舍五入的精度。length 必须是 tinyint、smallint 或int。当 length 为正数时,numeric_expression 四舍五入为 length 所指定的小数位数。当 length 为负数时,numeric_expression 则按 length 所指定的在小数点的左边四舍五入。function是要执行的操作类型。function 必须是 tinyint、smallint 或 int。如果省略 function 或 function 的值为 0(默认),numeric_expression 将四舍五入。当指定 0 以外的值时,将截断 numeric_expression。返回类型
返回与 numeric_expression 相同的类型。
SELECT ROUND(123.9994, 3), ROUND(123.9995, 3)
GO下面是结果集:----------- -----------
123.9990 124.0000 用ROUND 应该可以的
--方法2: Select round(0.00005,4) 结果: 0.00010