我用存储过程计算一个字段的值,结果出来的结果是以0.05单位保存的,搞不懂是怎么回事?
比如,结果为502.869, 它会保存为 502.90
478.405 会保存为478.45,总之所有的结果都是以  .50,.60 或.85,.35 等等以0.05为进制的结果
这是怎么回事啊
我的字段就是 numeric 类型 2位小数的啊

解决方案 »

  1.   

    cast(245.1551 as decimal(9,2))
      

  2.   

    哦?确实奇怪.尝试对结果使用cast(502.869 as decimal(18,2))
      

  3.   

    代码如下:
    CREATE proc gedeshui
    AS 
    begin
    declare @js numeric
    update gzk
    --js=yfgz_js+yj_lr-bj_js-ybjf_kk-grjf_kk-njgrjf_kk-gz_jt-fg_jt
    set @js=yfgz_js+yj_lr-bj_js-ybjf_kk-grjf_kk-njgrjf_kk-gz_jt-fg_jt,
          gds_js=(@js-
    case  when @js<=2000 then
       @js
            when @js>2000 then
       2000
    end
    )*
    case when @js<=2000 then
     0
    when @js>2000 and  @js<=2500 then
     0.05
     when @js>2500 and @js<=4000 then
      0.1
     when @js>4000 and @js<=7000 then
      0.15
     when @js>7000 then
       0.2
    end
    -
    case when @js<=2000 then
    0
     when @js>2000 and @js<=2500 then
    0
     when @js>2500 and @js<=4000 then
    25
     when @js>4000 and @js<=7000 then
    125
    when @js>7000 then
    375
     
    end     
    end
    GO
      

  4.   

    我把@js的结果赋值给一个字段,发现@js的结果是正常的保留2位小数的
      

  5.   


    就应该这样呀,两位就是四舍五入呀。
    select cast(502.869 as decimal(18,2))
      

  6.   

    Try:declare @js numeric 
    --->declare @js numeric (28,2)