diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-25 10:11:13 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-25 10:11:13 +0100 |
commit | 39510354d45f46e0f3d65c3a5d8f08be5ad680f3 (patch) | |
tree | 43697bf707d09a727928afd35cbc6c5634c952e1 /src/main/java/at/hannibal2/skyhanni/utils | |
parent | 368e75a26955703121bdb116503cf0544ad2e96a (diff) | |
download | skyhanni-39510354d45f46e0f3d65c3a5d8f08be5ad680f3.tar.gz skyhanni-39510354d45f46e0f3d65c3a5d8f08be5ad680f3.tar.bz2 skyhanni-39510354d45f46e0f3d65c3a5d8f08be5ad680f3.zip |
Made String.formatDouble() and formatLong()return nullable.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt | 11 |
1 files changed, 6 insertions, 5 deletions
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 |