首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么保留两位小数

2012-08-25 
如何保留两位小数?总次数 3776C# codedouble total DataGrid.cell(1,1).IntegerValue具体次数C# code

如何保留两位小数?
总次数 = 3776

C# code
double total = DataGrid.cell(1,1).IntegerValue;


具体次数

C# code
DataGrid.Cell(1, 2).Text = (((int)total * 0.01)).ToString();


使用了

C# code
math.round(xxx,2)


但是显示的是:整数 37

如何得到37.76呢?

[解决办法]
DataGrid.Cell(1, 2).Text = (total * 0.01).ToString(F2);//不要使用int,
[解决办法]
DataGrid.Cell(1, 2).Text = (((int)total * 0.01)).ToString();
真搞不懂你为什么给total转换成int类型,直接(total * 0.01).ToString();
真的多此一举

[解决办法]
ToString("0.00");
[解决办法]
应该不会啊,可以保留小数部分啊
C# code
int i = 3776;Console.Write(Math.Round(i * 0.01,2));  37.76 

热点排行