C# double保留四位小數


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

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

3.保留N位四舍五入

Math.Round(0.55555,4)

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

5.保留N位四舍五入

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

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

6. 保留N位四舍五入 (不錯)

double s=0.55555;
result=s.ToString("#0.0000");//點后面幾個0就保留幾位


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM