LibreTube/app/src/main/java/com/github/libretube/VideoViews.kt

23 lines
633 B
Kotlin
Raw Normal View History

2022-02-01 21:22:06 +05:30
package com.github.libretube
2022-01-19 22:22:32 +05:30
import java.math.BigDecimal
import java.math.RoundingMode
2022-02-15 02:26:32 +05:30
fun Long?.formatShort(): String = when {
2022-02-15 02:27:50 +05:30
this!! < 1000 -> {
this.toString()
}
this in 1000..999999 -> {
val decimal = BigDecimal(this / 1000).setScale(0, RoundingMode.HALF_EVEN)
decimal.toString() + "K"
}
this in 1000000..10000000 -> {
val decimal = BigDecimal(this / 1000000).setScale(0, RoundingMode.HALF_EVEN)
decimal.toString() + "M"
}
else -> {
val decimal = BigDecimal(this / 1000000).setScale(0, RoundingMode.HALF_EVEN)
decimal.toString() + "M"
}
}