You never know

This commit is contained in:
Alexandre Archambault 2016-11-01 13:19:37 +01:00
parent 57a5c1b83f
commit 9a43212040
No known key found for this signature in database
GPG Key ID: 14640A6839C263A9
1 changed files with 3 additions and 2 deletions

View File

@ -103,8 +103,9 @@ object TermDisplay {
if (bytes < unit)
bytes + " B"
else {
val exp = (math.log(bytes) / math.log(unit)).toInt
val pre = (if (si) "kMGTPE" else "KMGTPE").charAt(exp - 1) + (if (si) "" else "i")
val prefixes = if (si) "kMGTPE" else "KMGTPE"
val exp = (math.log(bytes) / math.log(unit)).toInt min prefixes.length
val pre = prefixes.charAt(exp - 1) + (if (si) "" else "i")
f"${bytes / math.pow(unit, exp)}%.1f ${pre}B"
}
}