All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xyz.erupt.monitor.util.SystemUtil Maven / Gradle / Ivy

There is a newer version: 1.12.15
Show newest version
package xyz.erupt.monitor.util;

import java.text.DecimalFormat;

/**
 * @author YuePeng
 * date 2021/1/23 23:45
 */
public class SystemUtil {

    //换算单位
    public static String formatByte(long byteNumber) {
        double FORMAT = 1024.0;
        double kbNumber = byteNumber / FORMAT;
        if (kbNumber < FORMAT) {
            return new DecimalFormat("#.##KB").format(kbNumber);
        }
        double mbNumber = kbNumber / FORMAT;
        if (mbNumber < FORMAT) {
            return new DecimalFormat("#.##MB").format(mbNumber);
        }
        double gbNumber = mbNumber / FORMAT;
        if (gbNumber < FORMAT) {
            return new DecimalFormat("#.##GB").format(gbNumber);
        }
        double tbNumber = gbNumber / FORMAT;
        return new DecimalFormat("#.##TB").format(tbNumber);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy