转自:http://blog.sina.com.cn/s/blog_4e6dffee0100cbc2.html

这里也有:http://www.diybl.com/course/4_webprogram/asp.net/netjs/20071112/85701.html

    1.只要求保留N位不四舍5入

    float f = 0.55555f;int i =(int)(f * 100);f = (float)(i*1.0)/100;

    2.保留N位,四舍五入 .

    decimal d= decimal.Round(decimal.Parse("0.55555"),2);

    3.保留N位四舍五入

    Math.Round(0.55555,2)

    4,保留N位四舍五入

    double dbdata = 0.55555;string str1 = dbdata.ToString("f2");//fN 保留N位,四舍五入

    5.保留N位四舍五入

    string result = String.Format("{0:N2}", 0.55555);//2位

    string result = String.Format("{0:N3}", 0.55555);//3位

    6. 保留N位四舍五入

    double s=0.55555;result=s.ToString("#0.00");//点后面几个0就保留几位

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-10-15
  • 2021-09-09
  • 2021-12-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案