From 3bc84f50fcb86abbe956c9ccbdf52cbdb563af47 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:50:03 +0100 Subject: Added String.formatLongOrUserError() --- src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (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 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(",", "") -- cgit