From 92854f66a7b42cbf59cd5708d8ee95e3c9cabc10 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Wed, 9 Nov 2022 18:46:35 +0700 Subject: [PATCH] Fix formatting of doubles and ints --- src/main/kotlin/ru/dbotthepony/mc/otm/core/Formatting.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Formatting.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Formatting.kt index c2f572442..5a4d9c717 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/Formatting.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/Formatting.kt @@ -375,13 +375,13 @@ fun ImpreciseFraction.formatSi(decimalPlaces: Int = 2): String { fun Int.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2): Component { require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" } val prefix = determineSiPrefix() ?: return if (suffix == "") TextComponent(toString()) else if (suffix is Component) TextComponent(toString() + " " + suffix.string) else TextComponent(toString() + " " + suffix) - return TranslatableComponent(prefix.formatLocaleKey, "%f.$decimalPlaces".format(this.toFloat() / prefix.int!!.toFloat()), suffix) + return TranslatableComponent(prefix.formatLocaleKey, "%.${decimalPlaces}f".format(this.toFloat() / prefix.int!!.toFloat()), suffix) } fun Double.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2): Component { require(decimalPlaces >= 0) { "Invalid amount of decimal places required: $decimalPlaces" } - val prefix = determineSiPrefix() ?: return if (suffix == "") TextComponent(toString()) else if (suffix is Component) TextComponent(toString() + " " + suffix.string) else TextComponent(toString() + " " + suffix) - return TranslatableComponent(prefix.formatLocaleKey, "%f.$decimalPlaces".format(this / prefix.double), suffix) + val prefix = determineSiPrefix() ?: return if (suffix == "") TextComponent("%.${decimalPlaces}f".format(this)) else if (suffix is Component) TextComponent("%.${decimalPlaces}f".format(this) + " " + suffix.string) else TextComponent("%.${decimalPlaces}f".format(this) + " " + suffix) + return TranslatableComponent(prefix.formatLocaleKey, "%.${decimalPlaces}f".format(this / prefix.double), suffix) } fun ImpreciseFraction.formatSiComponent(suffix: Any = "", decimalPlaces: Int = 2): Component {