Java Code Examples for com.blankj.utilcode.constant.MemoryConstants#GB
The following examples show how to use
com.blankj.utilcode.constant.MemoryConstants#GB .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConvertUtils.java From AndroidUtilCode with Apache License 2.0 | 6 votes |
/** * Size of byte to fit size of memory. * <p>to three decimal places</p> * * @param byteSize Size of byte. * @param precision The precision * @return fit size of memory */ @SuppressLint("DefaultLocale") public static String byte2FitMemorySize(final long byteSize, int precision) { if (precision < 0) { throw new IllegalArgumentException("precision shouldn't be less than zero!"); } if (byteSize < 0) { throw new IllegalArgumentException("byteSize shouldn't be less than zero!"); } else if (byteSize < MemoryConstants.KB) { return String.format("%." + precision + "fB", (double) byteSize); } else if (byteSize < MemoryConstants.MB) { return String.format("%." + precision + "fKB", (double) byteSize / MemoryConstants.KB); } else if (byteSize < MemoryConstants.GB) { return String.format("%." + precision + "fMB", (double) byteSize / MemoryConstants.MB); } else { return String.format("%." + precision + "fGB", (double) byteSize / MemoryConstants.GB); } }
Example 2
Source File: FileUtils.java From Android-UtilCode with Apache License 2.0 | 5 votes |
/** * 字节数转合适内存大小 * <p>保留3位小数</p> * * @param byteNum 字节数 * @return 合适内存大小 */ @SuppressLint("DefaultLocale") private static String byte2FitMemorySize(long byteNum) { if (byteNum < 0) { return "shouldn't be less than zero!"; } else if (byteNum < MemoryConstants.KB) { return String.format("%.3fB", (double) byteNum + 0.0005); } else if (byteNum < MemoryConstants.MB) { return String.format("%.3fKB", (double) byteNum / MemoryConstants.KB + 0.0005); } else if (byteNum < MemoryConstants.GB) { return String.format("%.3fMB", (double) byteNum / MemoryConstants.MB + 0.0005); } else { return String.format("%.3fGB", (double) byteNum / MemoryConstants.GB + 0.0005); } }
Example 3
Source File: ConvertUtils.java From Android-UtilCode with Apache License 2.0 | 5 votes |
/** * 字节数转合适内存大小 * <p>保留3位小数</p> * * @param byteNum 字节数 * @return 合适内存大小 */ @SuppressLint("DefaultLocale") public static String byte2FitMemorySize(long byteNum) { if (byteNum < 0) { return "shouldn't be less than zero!"; } else if (byteNum < MemoryConstants.KB) { return String.format("%.3fB", (double) byteNum + 0.0005); } else if (byteNum < MemoryConstants.MB) { return String.format("%.3fKB", (double) byteNum / MemoryConstants.KB + 0.0005); } else if (byteNum < MemoryConstants.GB) { return String.format("%.3fMB", (double) byteNum / MemoryConstants.MB + 0.0005); } else { return String.format("%.3fGB", (double) byteNum / MemoryConstants.GB + 0.0005); } }