如何将小数截断为小数为2位,比如3.888截断为3.88 如何将小数截断为小数为2位,比如3.888截断为3.88(不是四舍五入)3.556666截断为3.55 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 double a = 3.556666;int b = (int)(a * 100);a = ((float)b) / 100;Console.WriteLine(a.ToString());Console.ReadLine(); 先split('.')切成两半,后一半再用字符串函数取前两位,再合回去就行了呵呵,这个方法有点儿笨哦 我也来一个: double aaa = 3.88888888888888;string tmp = aaa.ToString("0.00");double result = Double.Parse( tmp ); double a = Convert.ToDouble(a.ToString(".00")); double a = 1213.22125; int i=a.ToString().IndexOf('.'); double b= double.Parse(a.ToString().Substring(0, i+3));b 就是要得到的数应该是对的吧快给分吧 算了,本来想看看.net有没有简单的方法可以调用的楼上的几个都不是太好如果我输1.1用上面的方法就出错要么就是给我输出1.10,其实我还是要1.1 搞笑了,以前好象用其他工具写,有现成的函数可以调用的,怎么在net找不到呢自己写个方法好了.. float a = 3.888888f;int b = (int)(a * 100);a = (float)a/100; float a = 3.888888f;a = Math.Floor(a*100)/100; double temp = 0.88998;string ccc = temp.ToString ("#0.00");temp = Convert.ToDouble (ccc); string str = "1.8"; string snew = ""; for (int i=0,j=0,ifind=0;i<str.Length&&j<2;i++) { if (ifind==1) j++; if (str[i] == '.') ifind = 1; snew += str[i]; }snew 就是了,感觉代码很垃圾,不管了能用就行了... decimal d=3.337;decimal dFormat = decimal.Floor(2m*100m)/100m; decimal d=3.337;decimal dFormat = decimal.Floor(d*100m)/100m; decimal d=3.337m;decimal dFormat = decimal.Floor(d*100m)/100m; string[] temp = str.Split('.'); string a = temp[1].ToString(); string c = temp[0].ToString(); string b = a.Substring(0, 2); string d = c + "." +b; 最快的实现方法:float fun (float fIn){ return float(int(fIn*100))/100;} 页面自动抓取软件 c#写一个程序模拟我的电脑 怎样验证CRC的正确性 dgvTestItems_CellEndEdit 调用 dgvTestItems_CellValidating 请问如何获取本机或者远程的端口啊??? 如何DataGrid中完成删除功能 如何让一个DataSet新增数据显示在第一行 读取EXCEL2007文档只读出来255列的数据,我这边每行1000个数据。求解~ 求解决一个警告 使用Socket模拟Http请求,如何提升性能? 谁有outlookbar控件(注册解密的) cookie在不同页面出现不一致的情况(字母和数字组合可以,用中文就不对了)
int b = (int)(a * 100);
a = ((float)b) / 100;
Console.WriteLine(a.ToString());
Console.ReadLine();
切成两半,后一半再用字符串函数取前两位,
再合回去就行了呵呵,这个方法有点儿笨哦
string tmp = aaa.ToString("0.00");
double result = Double.Parse( tmp );
double a = 1213.22125; int i=a.ToString().IndexOf('.'); double b= double.Parse(a.ToString().Substring(0, i+3));b 就是要得到的数
应该是对的吧
快给分吧
如果我输1.1用上面的方法就出错
要么就是给我输出1.10,其实我还是要1.1
自己写个方法好了..
int b = (int)(a * 100);
a = (float)a/100;
a = Math.Floor(a*100)/100;
string ccc = temp.ToString ("#0.00");
temp = Convert.ToDouble (ccc);
string snew = "";
for (int i=0,j=0,ifind=0;i<str.Length&&j<2;i++)
{
if (ifind==1)
j++;
if (str[i] == '.')
ifind = 1;
snew += str[i];
}snew 就是了,感觉代码很垃圾,不管了能用就行了...
decimal dFormat = decimal.Floor(2m*100m)/100m;
decimal dFormat = decimal.Floor(d*100m)/100m;
decimal dFormat = decimal.Floor(d*100m)/100m;
string a = temp[1].ToString();
string c = temp[0].ToString();
string b = a.Substring(0, 2);
string d = c + "." +b;
float fun (float fIn)
{
return float(int(fIn*100))/100;
}