JS 格式化文件大小单位

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/My_ben/article/details/83538468
// 格式化文件大小单位
function formatterSizeUnit(size) {
    if (size) {
        var result = parseInt(size);
        if (result < 1024) {
            return result + " B";
        } else if (result < 1024 * 1024) {
            return parseInt(result / 1024) + " KB";
        } else if (result < 1024 * 1024 * 1024) {
            return parseInt(result / (1024 * 1024)) + " MB";
        } else {
            return parseInt(result / (1024 * 1024 * 1024)) + " GB";
        }
    }
}

猜你喜欢

转载自blog.csdn.net/My_ben/article/details/83538468