create table numbers
(
n1 int,
n2 numberic(5,0),
n3 numberic(4,2)
)
go
insert numbers values(1.5,1.5,1.5)
select *
from numbers
go答案是1、2和1.50的结果集,我想问的是那个2怎么来的?

解决方案 »

  1.   

    四舍五入
    select cast(1.4 as numeric(5,0)) as num1,cast(1.5 as numeric(5,0)) as num2
    /**
    num1                                    num2
    --------------------------------------- ---------------------------------------
    1                                       2(1 行受影响)
    **/
      

  2.   

    numberic(5,0)-numeric(5,0)
    numeric(5,0)精度为0实际上就相当于int,只不过要四舍五入下
      

  3.   

     select cast(1.5 as int)num1,cast(1.5 as numeric(5,0)) as num2,cast(1.5 as numeric(4,2)) as num2结果就是1、2和1.50的结果集  numeric(5,0)小数点后位数为0,相当于将1.5四舍五入得到2  
      

  4.   


    膜拜树哥。你那个定义numeric(5,0)这个0实际上指的是小数点后面的位数为0,所以处理的时候就四舍五入了,1.5变成2鸟