aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-02-24 00:34:51 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-02-24 00:34:51 +0100
commitcf544583af30febdbe8ae0b20382f3f94fff0cb7 (patch)
treea569a5c5bf0a8003554ff5a9eb7d0e564bbd4a8b
parent4f3309f1f2d17e3cde4544dc9f6325b0d9bfd721 (diff)
downloadskyhanni-cf544583af30febdbe8ae0b20382f3f94fff0cb7.tar.gz
skyhanni-cf544583af30febdbe8ae0b20382f3f94fff0cb7.tar.bz2
skyhanni-cf544583af30febdbe8ae0b20382f3f94fff0cb7.zip
Created utils function String.formatDouble(): Double.
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
index 608bd2e11..60fb67213 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt
@@ -187,7 +187,10 @@ object NumberUtil {
}
}
- fun String.formatNumber(): Long {
+ // TODO create new function formatLong, and eventually deprecate this function.
+ fun String.formatNumber(): Long = formatDouble().toLong()
+
+ fun String.formatDouble(): Double {
var text = lowercase().replace(",", "")
val multiplier = if (text.endsWith("k")) {
@@ -201,7 +204,7 @@ object NumberUtil {
1.bilion
} else 1.0
val d = text.toDouble()
- return (d * multiplier).toLong()
+ return d * multiplier
}
val Int.milion get() = this * 1_000_000.0