C#保留2位小數總結

 

 

  1、

Math.Round(0.333333,2); //按照四捨五入的國際標準

  2、

double dbdata=0.335333
string str1=String.Format("{0:F}",dbdata);//默認爲保留兩位

  3、

float i=0.333333
int j=(int)(i * 100); 
= j/100

  4、

decimal.Round(decimal.Parse("0.3333333"),2

  5、

private System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo(); 
float test=0.333333f
nfi.NumberDecimalDigits
=2
string result=test.ToString("N", nfi); 

  6、   

string result= String.Format("{0:N2}",Convert.ToDecimal("0.333333").ToString()); 

  本文轉自:http://tmsoft.lsxy.com/index.php?load=read&id=138

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章