public static string convertUnitLengthLimit(long num, int most)
{
// string strNum = string.Empty + num;
string strNum = num.ToString("D");
if (strNum.Length <= most)
{
return num.ToString("n0");
}
most -= 1;
string[] unitStrs = { string.Empty, "K", "M", "B","T" }; //单位
int lost = 0;
while (strNum.Length - lost > most)
{
lost += 1;
}
int decimalsNum = 3 - (lost % 3);
if (decimalsNum == 3) decimalsNum = 0;
int unitIndex = (lost + decimalsNum) / 3;
while (unitIndex > 3)
{
lost -= 3;
unitIndex -= 1;
}
double mostShow = num / (double)Math.Pow(10, lost + decimalsNum);
return mostShow.ToString("N" + decimalsNum) + unitStrs[unitIndex];
}
这段代码定义了一个名为convertUnitLengthLimit的方法,用于将长整型数值转换为带有合适单位(如KB、MB等)的字符串,当数值过大时,会进行科学计数法表示。
1487

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



