Android bytes与KB、MB、GB单位转换 您所在的位置:网站首页 102400kb等于多少m Android bytes与KB、MB、GB单位转换

Android bytes与KB、MB、GB单位转换

2024-07-15 20:20| 来源: 网络整理| 查看: 265

1.先定义三个整型常量

//定义GB的计算常量 private static final int GB = 1024 * 1024 *1024; //定义MB的计算常量 private static final int MB = 1024 * 1024; //定义KB的计算常量 private static final int KB = 1024;

2.实现转换

public static String bytes2kb(long bytes){ //格式化小数 DecimalFormat format = new DecimalFormat("###.0"); if (bytes / GB >= 1){ return format.format(bytes / GB) + “GB”; } else if (bytes / MB >= 1){ return format.format(bytes / MB) + “MB”; } else if (bytes / KB >= 1){ return format.format(bytes / KB) + “KB”; }else { return bytes + “B”; } }



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有