欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP與C#分別格式化文件大小的代碼

 更新時間:2011年05月14日 15:40:52   作者:  
發(fā)現(xiàn)了一個格式化文件大小的方法, 很帥, 很簡潔, 尤其是 PHP 版的, 只需要 2 行代碼
PHP 版:
復制代碼 代碼如下:

function format($size)
{
$sizetext = array(" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return round($size/pow(1024,($i=floor(log($size,1024)))),2).$sizetext[$i];
}

C# 版:
復制代碼 代碼如下:

public string formatSize(long size)
{
if (size == 0) return "0";
string[] sizetext = new string[] { " B", " KB", " MB", " GB", " TB", " PB" };
int i = (int)Math.Floor(Math.Log(size, 1024));
return Math.Round(size / Math.Pow(1024, i), 2).ToString() + sizetext[i];
}

相關文章

最新評論