Fix format short when the count is null

This commit is contained in:
Bnyro 2022-10-28 21:52:26 +02:00
parent e598b745f6
commit 75ffce292c

View File

@ -3,15 +3,17 @@ package com.github.libretube.extensions
import java.math.BigDecimal import java.math.BigDecimal
import java.math.RoundingMode import java.math.RoundingMode
@Suppress("KotlinConstantConditions")
fun Long?.formatShort(): String = when { fun Long?.formatShort(): String = when {
this!! < 1000 -> { this == null -> (0).toString()
this < 1000 -> {
this.toString() this.toString()
} }
this in 1000..999999 -> { this in (1000..999999) -> {
val decimal = BigDecimal(this / 1000).setScale(0, RoundingMode.HALF_EVEN) val decimal = BigDecimal(this / 1000).setScale(0, RoundingMode.HALF_EVEN)
decimal.toString() + "K" decimal.toString() + "K"
} }
this in 1000000..10000000 -> { this in (1000000..10000000) -> {
val decimal = BigDecimal(this / 1000000).setScale(0, RoundingMode.HALF_EVEN) val decimal = BigDecimal(this / 1000000).setScale(0, RoundingMode.HALF_EVEN)
decimal.toString() + "M" decimal.toString() + "M"
} }