1package com.parseable.android.data
5private val BYTE_UNITS = arrayOf("B", "KB", "MB", "GB", "TB", "PB")
8 * Converts a raw byte-count string (e.g. "123456789") to a human-readable
9 * size (e.g. "117.7 MB"). If the string is not a valid number, it is
10 * returned unchanged so pre-formatted values from the API pass through.
12fun formatBytes(raw: String?): String? {
13 if (raw == null) return null
14 val bytes = raw.trim().toDoubleOrNull() ?: return raw
15 if (bytes < 0) return raw
16 if (bytes < 1024) return String.format(Locale.US, "%.0f B", bytes)
19 while (value >= 1024 && unitIndex < BYTE_UNITS.size - 1) {
23 return if (value >= 100) {
24 String.format(Locale.US, "%.0f %s", value, BYTE_UNITS[unitIndex])
25 } else if (value >= 10) {
26 String.format(Locale.US, "%.1f %s", value, BYTE_UNITS[unitIndex])
28 String.format(Locale.US, "%.2f %s", value, BYTE_UNITS[unitIndex])
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list