formatBytes

fun Long.formatBytes(decimals: Int = 1, si: Boolean = false): String

Formats this byte count as a human-readable size string such as "1.5 KiB".

With si false (the default) the base is 1024 and the unit ladder is B, KiB, MiB, GiB, TiB, PiB, EiB. With si true the base is 1000 and the ladder is B, kB, MB, GB, TB, PB, EB. The largest unit whose base power does not exceed the magnitude is chosen. Plain byte values are printed without decimals ("512 B"); scaled values use Double.formatDecimals with decimals digits and half-up rounding, so a value close to the next unit may print as the base, for example "1024.0 KiB". Negative counts keep a leading minus sign. Throws IllegalArgumentException when decimals is outside 0..15.