当前位置:首页 > PHP教程 > PHP高级教程

PHP与C#分别格式化文件大小的代码

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];
}


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!