diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-26 16:50:03 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-02-26 16:50:03 +0100 |
commit | 3bc84f50fcb86abbe956c9ccbdf52cbdb563af47 (patch) | |
tree | 3acbd598220fee7b40894aa664e0993b43e3cdb5 /src/main/java/at/hannibal2/skyhanni/utils | |
parent | ab737fe92e2631be619c8613da167dd8aab7984b (diff) | |
download | skyhanni-3bc84f50fcb86abbe956c9ccbdf52cbdb563af47.tar.gz skyhanni-3bc84f50fcb86abbe956c9ccbdf52cbdb563af47.tar.bz2 skyhanni-3bc84f50fcb86abbe956c9ccbdf52cbdb563af47.zip |
Added String.formatLongOrUserError()
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt index 390516e0a..b481eff35 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt @@ -189,10 +189,15 @@ object NumberUtil { // TODO create new function formatLong, and eventually deprecate this function. @Deprecated("renamed", ReplaceWith("this.formatLong()")) - fun String.formatNumber(): Long = formatLong() ?: error("formatNumber has a NumberFormatException with '$this'") + fun String.formatNumber(): Long = formatLong() ?: throw NumberFormatException("formatNumber has a NumberFormatException with '$this'") fun String.formatLong(): Long? = formatDouble()?.toLong() + fun String.formatLongOrUserError(): Long? = formatDouble()?.toLong() ?: run { + ChatUtils.userError("Not a valid number: '$this'") + return@run null + } + fun String.formatDouble(): Double? { var text = lowercase().replace(",", "") |