From 39510354d45f46e0f3d65c3a5d8f08be5ad680f3 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 25 Feb 2024 10:11:13 +0100 Subject: Made String.formatDouble() and formatLong()return nullable. --- src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt index 6deee85bc..390516e0a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt @@ -189,11 +189,11 @@ object NumberUtil { // TODO create new function formatLong, and eventually deprecate this function. @Deprecated("renamed", ReplaceWith("this.formatLong()")) - fun String.formatNumber(): Long = formatLong() + fun String.formatNumber(): Long = formatLong() ?: error("formatNumber has a NumberFormatException with '$this'") - fun String.formatLong(): Long = formatDouble().toLong() + fun String.formatLong(): Long? = formatDouble()?.toLong() - fun String.formatDouble(): Double { + fun String.formatDouble(): Double? { var text = lowercase().replace(",", "") val multiplier = if (text.endsWith("k")) { @@ -206,8 +206,9 @@ object NumberUtil { text = text.substring(0, text.length - 1) 1.bilion } else 1.0 - val d = text.toDouble() - return d * multiplier + return text.toDoubleOrNull()?.let { + it * multiplier + } } val Int.milion get() = this * 1_000_000.0 -- cgit