C# 數字轉換成百分比數
deciaml percent = 0.123456789123456789M;
//12345.ToString("p"); 生成 1,234,500.00%
string q1 = percent.ToString("P"); //12.35%;自動四捨五入,百分數,千位分隔,自動兩個小數
string q2 = percent.ToString("P0"); //12%;P後邊跟數字,代表精度。
string q3 = percent.ToString("P1"); //12.3%;
string q4 = percent.ToString("P2"); //12.35%;
string q5 = percent.ToString("P3");
string q6 = percent.ToString("P4");
string q7 = percent.ToString("P5");
string q8 = percent.ToString("P6");
//當然你還可以用一下方式:
decimal percent =0.24015M;
string q9 = percent.ToString("0.##%"); //得到 "24.02%"
//##個數表示保留的小數位數(必要時四捨五入)
學習是一種樂趣~Come On