首页 > 编程语言 >java文件大小单位转换

java文件大小单位转换

时间:2022-09-28 11:24:18浏览次数:56  
标签:fileS 文件大小 java String format df double fileSizeString 转换

private String formatSize(long fileS) {
        DecimalFormat df = new DecimalFormat("#.00");
        String fileSizeString = "";
        String wrongSize = "0B";
        if (fileS == 0) {
            return wrongSize;
        }
        if (fileS < 1024) {
            fileSizeString = df.format((double) fileS) + "B";
        } else if (fileS < 1048576) {
            fileSizeString = df.format((double) fileS / 1024) + "KB";
        } else if (fileS < 1073741824) {
            fileSizeString = df.format((double) fileS / 1048576) + "MB";
        } else {
            fileSizeString = df.format((double) fileS / 1073741824) + "GB";
        }
        return fileSizeString;
    }

 

标签:fileS,文件大小,java,String,format,df,double,fileSizeString,转换
From: https://www.cnblogs.com/Objecting/p/16737327.html

相关文章