A列               B列
350.000000   55555.55当B列除于A列时,在SQL结果是170.940153小数保留6位,但没有计算没有四舍五入
55555.55/350.000000=170.940153846153为什么没有四舍五入呢?要怎么才能四舍五入呢??

解决方案 »

  1.   

    select cast(a/b as decimal(18,6))
      

  2.   

    declare @a as decimal(18,6)
    declare @b as decimal(18,6)set @a = 350.000000  
    set @b = 55555.55 select cast(@b/@a as decimal(18,6))/*
                         
    -------------------- 
    158.730143(所影响的行数为 1 行)
    */
      

  3.   

    select cast(B列/A列 as decimal(18,6))
      

  4.   

    使用ROUND(四舍五入)函数
    ROUND函数用于将数字表达式四舍五入为指定的长度或精度。语法: ROUND ( numeric_expression , length [ , function ] ) 参数说明:l          numeric_expression:精确数字或近似数字数据类型类别的表达式(bit数据类型除外)。l          length:为四舍五入的精度。length必须是tinyint、smallint或int。当length为正数时,numeric_expression四舍五入为length所指定的小数位数。当length为负数时,numeric_expression则按length所指定的在小数点的左边四舍五入。l          function:要执行的操作类型。SELECT ROUND(123.1994,3) AS "取小数点后3位 "   123.1990SELECT ROUND(123.1995,3) AS "取小数点后3位"    123.2000