1 方法一:
 2     decimal d= decimal.Round(decimal.Parse("0.55555"),2);  
 3 方法二:
 4 Math.Round(0.55555,2)  
 5 方法三:
 6 double dbdata = 0.55555;   
 7 string str1 = dbdata.ToString("f2");//fN 保留N位,四舍五入 
 8 方法四:
 9 string result = String.Format("{0:N2}", 0.55555);//2位   
10  
11 string result = String.Format("{0:N3}", 0.55555);//3位 
12 方法五:
13 double s=0.55555;   
14 result=s.ToString("#0.00");//点后面几个0就保留几位 
C#保留小数位N位,四舍五入

相关文章:

  • 2021-11-14
  • 2022-01-02
  • 2021-11-28
  • 2021-11-16
  • 2022-02-27
  • 2021-11-28
  • 2021-10-29
  • 2021-10-21
猜你喜欢
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案