2。protected string FormatMoney(string FMoney)
{
string money = FMoney;
int postion = 0;
if (money.IndexOf('.') < 0)
{
postion = money.Length;
}
else
{
postion = money.IndexOf('.');
}
int maxfor = postion / 3;
int re = (int)postion % 3;
StringBuilder aa = new StringBuilder();
if (re != 0)
{
aa.Append(money.Substring(0, re));
for (int i = 0; i < maxfor; i++)
{
aa.Append(",");
aa.Append(money.Substring(re, 3));
re = re + 3;
}
}
else
{
re = 3;
aa.Append(money.Substring(0, re));
for (int j = 0; j < maxfor - 1; j++)
{
aa.Append(",");
aa.Append(money.Substring(re, 3));
re = re + 3;
}
}
aa.Append(money.Substring(postion));
return aa.ToString();
}
本文介绍了一种使用 C# 实现的货币数值格式化方法,该方法可以将输入的字符串形式的金额转换为易于阅读的形式,如添加千位分隔符等。
4966

被折叠的 条评论
为什么被折叠?



