Here you can find the source of humanReadableByteCount(long bytes, boolean si)
Parameter | Description |
---|---|
bytes | a parameter |
si | a parameter |
public static String humanReadableByteCount(long bytes, boolean si)
//package com.java2s; public class Main { /**/*from w w w . j a v a2s .com*/ * PURPOSE: <br> * humanReadableByteCount<br> * <br> * * @param bytes * @param si * @return<br> */ public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); } }