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 formatFileSize(bytes,decimalPoint) { | |
if(bytes == 0) return '0 Bytes'; | |
var k = 1000, | |
dm = decimalPoint || 2, | |
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], | |
i = Math.floor(Math.log(bytes) / Math.log(k)); | |
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; | |
} | |
//You only need to use the formatFileSize() function in JavaScript to convert file size units. |