String (long contentLengthInBytes) { if (contentLengthInBytes < 0) { return ""; } final int kilo = 1024; if (contentLengthInBytes < kilo) { return ", " + contentLengthInBytes + " bytes"; } if (contentLengthInBytes < kilo * kilo) { return String.format(Locale.US, ", %.1f kB", contentLengthInBytes / (1.0 * kilo)); } return String.format(Locale.US, ", %.1f MB", contentLengthInBytes / (1.0 * kilo * kilo)); }