xyz.erupt.monitor.util.SystemUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of erupt-monitor Show documentation
Show all versions of erupt-monitor Show documentation
erupt monitor → redis / server
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);
}
}