C# decimal保留两位小数

C# decimal保留两位小数

*solution 1 个人推荐 最简单

decimal d = 46.28111;

string dStr = Math.Round( d,2 ).ToString();

*solution 2

decimal a = 46.28111;
string result=a.ToString("#0.00");

*solution 3

decimal d = 46.28111m;
string res=d.ToString("#0.00");

*solution 4

double d=45.123456;
string res=double.Parse(String.Format("{0:N}", d)).ToString();

Guess you like

Origin blog.csdn.net/qq_43469252/article/details/102913574