我在做一个报表 ,基本计算都是在数据库中进行的 ,我们需要精确的数据,可是得到的结果却不对,都是四舍五入以后的数值了 ,比如,应该值是0.4000,可在gridview中的值则显示为0.0000.请高手指点。我的计算过程如下:
begin 

   select  @return_nl=
   case
      when @tag='yzsjnl' then (select sum(dnxz_yzsj_dy) from dbo.zsxthdlgc_6 
         
           where sj<=@sj and substring(sj,1,4)=substring(@sj,1,4) and xdbm=@xdbm and xm=@xm)
     
      when @tag='hdnl' then (select sum(dnxz_hd_dy) from dbo.zsxthdlgc_6  
        
           where sj<=@sj and substring(sj,1,4)=substring(@sj,1,4) and xdbm=@xdbm and xm=@xm)
     
      when @tag='cllnl' then (select sum(dnxz_cll_dy) from dbo.zsxthdlgc_6  
      
           where sj<=@sj and substring(sj,1,4)=substring(@sj,1,4) and xdbm=@xdbm and xm=@xm)
     
      when @tag='dhnl' then (select sum(dnxz_hd_dy) from dbo.zsxthdlgc_6 
       
           where sj<=@sj and substring(sj,1,4)=substring(@sj,1,4) and xdbm=@xdbm and xm=@xm)/
       
           (select sum(dnxz_cll_dy) from dbo.zsxthdlgc_6  where sj<=@sj and substring(sj,1,4)=substring(@sj,1,4)
          and xdbm=@xdbm and xm=@xm)
   end

   end

解决方案 »

  1.   

    设置下gridview中结果列的格式。
      

  2.   

    设置下gridview中结果列的格式。
      

  3.   

    造成樓主所述結果是因為SQL中查詢字段申明為Int類型樓主可在查詢時將其轉換成float類型示例declare @test table
    (
    name varchar(20) not null,
    qty int not null
    )insert into @test
    select 'test1',9 union all
    select 'test2',4 union all
    select 'test3',3 select sum(cast(qty as float)/5 ) from @test
      

  4.   

    我在gridview中的未使用数据库函数的列都没有问题,所有的列的设置相同 ,所以不存在gridview的问题。,详细的说一下,就是我上面的是根据时间的不同,将本有和前几个月的数据相加产生的 ,而相加后就出现了这个问题,这是怎么回事呢 。
      

  5.   

    问题已经解决,是数据库的问题,在建表的时候decimal没有指定位数,麻烦大家。
      

  6.   

    @return_nl这个返回值的类型是什么,按理应该是和sum函数里的字段是同一个数据类型,不过你根据条件要返回不同字段的和,所以这个返回值的类型就比较关键了。如果是float或real应该是没问题(对应gridview中结果列的格式是允许4位小数)。
    如果是其他的类型,你就要对应修改了。