在WinForm里面给DataGridView绑定数据,数据源是DataSet
这是我的查询语句
SELECT OpUser.Oname as '收银员',sum( BeginTableDetail.DefineNum) as '总数', sum(BeginTableDetail.FavNum) as '总金额' ,sum((BeginTableDetail.defineNum * PresentsDefine.Price)-(BeginTableDetail.FavNum)) as '总优惠金额' FROM BeginTableDetail INNER JOIN BeginTable ON BeginTableDetail.BeginTableId = BeginTable.BID INNER JOIN PresentsDefine ON BeginTableDetail.PresentsDefineId = PresentsDefine.Id INNER JOIN OpUser ON BeginTable.StaffId = OpUser.Oid group by oname总金额这一列显示的时候是:20.000000000000000000000  我想让它格式化输出成这种效果:¥20.00
因为我用的数据源是DataSet所以页面设计时就没有编辑列
这是页面
只能在代码里写格式化输出的了,可是不知道怎么写,向各位高手求助

解决方案 »

  1.   

    Convert(money,sum(BeginTableDetail.FavNum)) as '总金额' 
      

  2.   

    Convert(money,sum(BeginTableDetail.FavNum)) as '总金额'
      

  3.   

    ASP.NET 参考下double aaa=123556.2364;
    //this is C2 result:¥123,556.24
    Response.Write(string.Format(&"this is C2 result:{0:C2}&", aaa)+&"<br/>&");
    //this is F2 result: 123556.24
    Response.Write(string.Format(&"this is F2 result:{0,10:F2}&", aaa) + &"<br/>&");
      

  4.   

    把这个稍微修改下就可以了,主要就是用到string.Format方法。
      

  5.   

     string s=string.Format("{0:C2}",20);
     MessageBox.Show(s);按照这种转换方式你可以循环datagridview的那一列 重新赋值啊 
      

  6.   

    string s=string.Format("{0:C2}",20);
      

  7.   


    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                if (e.ColumnIndex == 3 )//你想要的列
                {
                    e.Value = double.Parse(e.Value.ToString()).ToString("N");
                }
            }
      

  8.   

    最好能在SQL里一并处理了比较好吧!~
      

  9.   

    关注中,我用的方法比较笨,先遍历dataset,把该改的都改了以后,再绑定
      

  10.   

    doublevalue  = 20.00000000000000000declare @a as decimal(18, 10)
    select @a= (select doublevalue from Test where id = 1)
    declare @x  as decimal(18, 10)
    --select @str ='$'+ str(SELECT CAST(@a as decimal(18, 2)),6,2)
    select @x =(SELECT CAST(@a as decimal(18, 2)))
    declare @b  as varchar(100)
    select @b = '$'
    declare @c  as varchar(100)
    select @c = @b+str(@x,6,2)
    select @c from Test where id= 1 自己写个存储过程或者直接执行这个Sql语句,做下格式化转换,我写的比较繁琐,请楼主自己优化。