递归法
public long GetLength(double data, int i, out int index)
{
index = i;
long temp = (long )(data / 1024);
while (temp > 1024)
{
i++;
temp = GetLength(temp, i, out index);
}
return temp;
}
public string ConvertDiskSpace(long res, int index)
{
string diskSize = "";
switch (index)
{
case 0:
diskSize = $"{res.ToString("0.00")}B";
break;
case 1:
diskSize = $"{res.ToString("0.00")}KB";
break;
case 2:
diskSize = $"{res.ToString("0.00")}MB";
break;
case 3:
diskSize = $"{res.ToString("0.00")}GB";
break;
case 4:
diskSize = $"{res.ToString("0.00")}TB";
break;
default:
break;
}
return diskSize;
}
网友评论