From d9eed2f1242005c7bd05a66009d07e87c2fa7915 Mon Sep 17 00:00:00 2001 From: GeorgCantor Date: Mon, 23 Sep 2024 16:51:56 +0300 Subject: [PATCH] Update NumberKtx.kt (#960) **Background** Simplified **Changes** Shortened the code **Test plan** Eye test --- .../com/flipperdevices/core/ktx/jre/NumberKtx.kt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/components/core/ktx/src/commonMain/kotlin/com/flipperdevices/core/ktx/jre/NumberKtx.kt b/components/core/ktx/src/commonMain/kotlin/com/flipperdevices/core/ktx/jre/NumberKtx.kt index 6b37bc8f64..3a30367921 100644 --- a/components/core/ktx/src/commonMain/kotlin/com/flipperdevices/core/ktx/jre/NumberKtx.kt +++ b/components/core/ktx/src/commonMain/kotlin/com/flipperdevices/core/ktx/jre/NumberKtx.kt @@ -13,19 +13,11 @@ private const val PERCENT_MAX = 100 * If not, return Int.MIN_VALUE or Int.MAX_VALUE */ fun Long.toIntSafe(): Int { - if (this > Int.MAX_VALUE) { - return Int.MAX_VALUE - } - - if (this < Int.MIN_VALUE) { - return Int.MIN_VALUE - } - - return this.toInt() + return coerceIn(Int.MIN_VALUE.toLong(), Int.MAX_VALUE.toLong()).toInt() } fun Float.roundPercentToString(): String { - val processedPercent = if (this > 1.0f) 1.0f else if (this < 0.0f) 0.0f else this + val processedPercent = coerceIn(0.0f, 1.0f) return "${(processedPercent * PERCENT_MAX).roundToInt()}%" }