C# 金钱添加逗号0000
private void Form1_Load(object sender, EventArgs e) { decimal dd = (decimal)11234567890.01; string ddstr = dd.ToString(); test(ddstr); } public void test(string num_str) { if (num_str.IndexOf(".") != -1) { //小数 string[] strlist = num_str.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);//返回值不包含空字符串元素, var 整数 = strlist[0]; var 小数 = strlist[1]; var arry_int = 整数.ToArray(); StringBuilder sb = new StringBuilder(); var t = Math.Floor((double)整数.Length / 3); if (arry_int.Length % 3 == 0) { for (int i = 0; i < arry_int.Length; i++) { if (i % 3 == 0 && i != 0) { sb.Append(","); sb.Append(arry_int[i]); continue; } sb.Append(arry_int[i]); } } else { var t0 = arry_int.Length - (t * 3); for (int i = 0; i < arry_int.Length; i++) { if ((i-t0) % 3 == 0 && i != 0) { sb.Append(","); sb.Append(arry_int[i]); continue; } sb.Append(arry_int[i]); } } var result = sb.ToString(); } }