- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
enum class Measures {
B, KB, MB, GB;
private val size = BigDecimal.valueOf(1024L).pow(ordinal)
companion object {
fun toHumanSize(value: Long): String {
val decValue = value.toBigDecimal()
val measure = values().reversed().find { it.size < decValue } ?: B
return "${decValue.divide(measure.size, 3, RoundingMode.UP)} $measure"
}
}
}