package cn.bunny.common.utils;

public class FileUtil {
    public static String getSize(Long fileSize) {
        double fileSizeInKB = fileSize / 1024.00;
        double fileSizeInMB = fileSizeInKB / 1024;
        double fileSizeInGB = fileSizeInMB / 1024;

        String size;
        if (fileSizeInGB >= 1) {
            fileSizeInGB = Double.parseDouble(String.format("%.2f", fileSizeInGB));
            size = fileSizeInGB + "GB";
        } else if (fileSizeInMB >= 1) {
            fileSizeInMB = Double.parseDouble(String.format("%.2f", fileSizeInMB));
            size = fileSizeInMB + "MB";
        } else if (fileSizeInKB >= 1) {
            fileSizeInKB = Double.parseDouble(String.format("%.2f", fileSizeInKB));
            size = fileSizeInKB + "KB";
        } else {
            size = fileSize + "B";
        }

        return size;
    }
}
