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

前端之家收集整理的这篇文章主要介绍了PHP与C#分别格式化文件大小的代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

PHP 版:
<div class="codetitle"><a style="CURSOR: pointer" data="8738" class="copybut" id="copybut8738" onclick="doCopy('code8738')"> 代码如下:

<div class="codebody" id="code8738">
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# 版:
<div class="codetitle"><a style="CURSOR: pointer" data="452" class="copybut" id="copybut452" onclick="doCopy('code452')"> 代码如下:
<div class="codebody" id="code452">
public string formatSize(long size)
{
if (size == 0) return "0";
string[] sizetext = new string[] { " B"," PB" };
int i = (int)Math.Floor(Math.Log(size,1024));
return Math.Round(size / Math.Pow(1024,i),2).ToString() + sizetext[i];
}

原文链接:https://www.f2er.com/php/27983.html

猜你在找的PHP相关文章