diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-09-23 17:19:44 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2024-09-23 17:19:44 +0200 |
commit | a8be86761f6302894346498df121a499be3f93ad (patch) | |
tree | cf8aaefa3c9f4200e43709485327a60d0d4e6fa6 /src/main/java/at | |
parent | 2eed7efac2dab7ec54043d188d814b17052cebdd (diff) | |
download | skyhanni-a8be86761f6302894346498df121a499be3f93ad.tar.gz skyhanni-a8be86761f6302894346498df121a499be3f93ad.tar.bz2 skyhanni-a8be86761f6302894346498df121a499be3f93ad.zip |
fix rounding
Diffstat (limited to 'src/main/java/at')
3 files changed, 6 insertions, 8 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentsProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentsProfitTracker.kt index 7b6fa9bc5..6e755d874 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentsProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/experimentationtable/ExperimentsProfitTracker.kt @@ -25,10 +25,10 @@ import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPrice import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.roundTo import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher import at.hannibal2.skyhanni.utils.RegexUtils.matches @@ -162,7 +162,7 @@ object ExperimentsProfitTracker { val price = internalName.getPrice() val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0 val maxPrice = npcPrice.coerceAtLeast(price) - startCostTemp += maxPrice.round(0).toInt() + startCostTemp += maxPrice.roundTo(0).toInt() iterator.remove() } tracker.modify { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index cd96121c4..e4e74b0d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -101,10 +101,10 @@ object LorenzUtils { return originalMessage.stripHypixelMessage() } - @Deprecated("Use roundTo instead", ReplaceWith("this.roundTo(precision)")) + @Deprecated("Use roundTo instead", ReplaceWith("this.roundTo(decimals)")) fun Double.round(decimals: Int) = this.roundTo(decimals) - @Deprecated("Use roundTo instead", ReplaceWith("this.roundTo(precision)")) + @Deprecated("Use roundTo instead", ReplaceWith("this.roundTo(decimals)")) fun Float.round(decimals: Int) = this.roundTo(decimals) // TODO replace all calls with regex diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt index 58441ecab..dc7c4828c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NumberUtil.kt @@ -83,12 +83,10 @@ object NumberUtil { */ fun Double.roundTo(precision: Int): Double { val scale = 10.0.pow(precision) - return kotlin.math.round(scale) / scale + return kotlin.math.round(this * scale) / scale } - fun Float.roundTo(precision: Int): Float { - return toDouble().roundTo(precision).toFloat() - } + fun Float.roundTo(precision: Int): Float = toDouble().roundTo(precision).toFloat() @Deprecated("Use roundTo instead", ReplaceWith("this.roundTo(precision)")) fun Double.roundToPrecision(precision: Int) = this.roundTo(precision) |