private static StringBuilder ret = new StringBuilder(13);
public static string FormateGoldString(string gold)
{
ret.Remove(0, ret.Length);
int length = gold.Length;
string result = string.Empty;
if (length > 2)
{
ret.Append(gold.Substring(0, length - 2));
string str2 = gold.Substring(length - 2, 2);
if (str2 != "00")
{
ret.Append(".");
if (str2[1] == '0')
{
ret.Append(str2[0]);
}
else
{
ret.Append(str2);
}
}
}
else
{
if (length == 1)
{
if (gold == "0")
{
ret.Append(0);
}
else
{
ret.Append("0.0");
ret.Append(gold);
}
}
else
{
ret.Append("0.");
if (gold[1] == '0')
{
ret.Append(gold[0]);
}
else
{
ret.Append(gold);
}
}
}
return ret.ToString();
}很简单的就是分析各种可能出现的情况,将小数部分提取出来,加个点连接起来。