Created
September 26, 2011 08:26
-
-
Save yangg/1241850 to your computer and use it in GitHub Desktop.
Format Filesize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.cnblogs.com/yaob/archive/2011/05/14/2046013.html | |
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]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatSize(size) { | |
var sizetext = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | |
i = Math.floor(Math.log(size)/Math.log(1024)); | |
return (size/Math.pow(1024, i)).toFixed(2) + ' ' + sizetext[i]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment