Java实现存储单位转换

存储单位转换工具

  • 1 Kilo Byte(KB) = 1024 Byte(B)
  • 1 Mega Byte(MB) = 1024 KB
  • 1 Giga Byte (GB)= 1024 MB
  • 1 Tera Byte(TB)= 1024 GB
  • 1 Peta Byte(PB) = 1024 TB
/**
 * 存储单位转换工具
 * 
 * @author volitation
 *
 */
public class HexTransformationUtils {

    /**
     * byte 转 TB
     * 
     * @param number
     * @return
     */
    public static Integer byteTurnTb(Long number){
        Long standard = 1024*1024*1024*1024L;
        Long calculation = (long) (number/standard*0.9);
        Integer result = calculation.intValue();
        return result;
    }

    /**
     * GB 转 TB
     *
     * @param number
     * @return
     */
    public static Integer gbTurnTb(Integer number){
        Integer standard = 1024;
        Integer result = (int) (number/standard*0.9);
        return result;
    }

    /**
     * KB 转 GB
     * 
     * @param number
     * @return
     */
    public static Integer kbTurnGb(Integer number){
        Integer standard = 1024*1024;
        Integer result = (int) (number/standard*0.9);
        return result;
    }


}

猜你喜欢

转载自blog.csdn.net/volitationlong/article/details/79897979