package com.hainaos.vc.utils;

import java.text.DecimalFormat;

public class FileUtils {
    /**
     * 转换文件大小 MB
     */
    public static String formatFileSize(long fileS) {
        DecimalFormat df = new DecimalFormat("#");
        String fileSizeString;
        String wrongSize = "0GB";
        if (fileS == 0) {
            return wrongSize;
        }
        if (fileS < 1024) {
            fileSizeString = df.format((double) fileS) + "MB";
        } else if (fileS < 1048576) {
            fileSizeString = df.format((double) fileS / 1024) + "GB";
        } else {
            fileSizeString = df.format((double) fileS / 1048576) + "TB";
        }
        return fileSizeString;
    }
}
