方法一
//缩写金币
public static string AcCoin(long gold) {
string str = "";
long k = (long)Mathf.Pow(10, 3);
long m = (long)Mathf.Pow(10, 6);
long b = (long)Mathf.Pow(10, 9);
long t = (long)Mathf.Pow(10, 12);
if (gold >= t)
str = (gold / (double)t).ToString("0.0") + "t";
else if (gold >= b)
str = (gold / (double)b).ToString("0.0") + "b";
else if (gold >= m)
str = (gold / (double)m).ToString("0.0") + "m";
else if (gold >= k)
str = (gold / (double)k).ToString("0.0") + "k";
else
str = gold.ToString();
return str;
}
方法二
public static string GetSuffix(int num) {
string suffix = "";
string s = num.ToString();
if (num < 10000) return num.ToString();
switch ((s.Length - 1) / 3) {
case 0:
suffix = string.Empty;
break;
case 1:
suffix = "K";
break;
case 2:
suffix = "M";
break;
case 3:
suffix = "B";
break;
case 4:
suffix = "T";
break;
case 5:
suffix = "Qa";
break;
case 6:
suffix = "Qi";
break;
case 7:
suffix = "S";
break;
}
if (s.Length % 3 == 1)
return s.Substring(0, 1) + "." + s.Substring(1, 1) + s.Substring(2, 1) + suffix; // 4.35m
if (s.Length % 3 == 2)
return s.Substring(0, 1) + s.Substring(1, 1) + "." + s.Substring(2, 1) + suffix; // 4.35m
if (s.Length % 3 == 0)
return s.Substring(0, 1) + s.Substring(1, 1) + s.Substring(2, 1) + suffix; // 4.35m
return "";
}
总结
都是传递你希望变化的金币数量进入方法中,实在你想要的金币效果