From 3ec52cae4bd0d480a65792cd66cf4c00d70f46ec Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Sun, 9 Jul 2023 10:48:34 +0800 Subject: [PATCH] move decimal format to TextUtil --- forge-core/src/main/java/forge/util/TextUtil.java | 4 ++++ .../src/forge/adventure/scene/PlayerStatisticScene.java | 7 ++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/forge-core/src/main/java/forge/util/TextUtil.java b/forge-core/src/main/java/forge/util/TextUtil.java index 9496391736a..5854c0a0223 100644 --- a/forge-core/src/main/java/forge/util/TextUtil.java +++ b/forge-core/src/main/java/forge/util/TextUtil.java @@ -42,6 +42,10 @@ public class TextUtil { return Normalizer.normalize(text, Normalizer.Form.NFD); } + private static final DecimalFormat df = new DecimalFormat("#.##"); + public static String decimalFormat(float value) { + return df.format(value); + } /** * Safely converts an object to a String. * diff --git a/forge-gui-mobile/src/forge/adventure/scene/PlayerStatisticScene.java b/forge-gui-mobile/src/forge/adventure/scene/PlayerStatisticScene.java index 94992e38bc3..9b224eb2e1d 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/PlayerStatisticScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/PlayerStatisticScene.java @@ -32,9 +32,9 @@ import forge.localinstance.achievements.CardActivationAchievements; import forge.localinstance.achievements.PlaneswalkerAchievements; import forge.model.FModel; import forge.player.GamePlayerUtil; +import forge.util.TextUtil; import org.apache.commons.lang3.tuple.Pair; -import java.text.DecimalFormat; import java.util.Map; public class PlayerStatisticScene extends UIScene { @@ -53,7 +53,6 @@ public class PlayerStatisticScene extends UIScene { boolean toggle = false; AchievementCollection planeswalkers, achievements, cardActivation; Scene lastGameScene; - DecimalFormat df; private PlayerStatisticScene() { super(Forge.isLandscapeMode() ? "ui/statistic.json" : "ui/statistic_portrait.json"); @@ -218,9 +217,7 @@ public class PlayerStatisticScene extends UIScene { totalLoss.setText(String.valueOf(Current.player().getStatistic().totalLoss())); } if (lossWinRatio != null) { - if (df == null) - df = new DecimalFormat("#.##"); - lossWinRatio.setText(df.format(Current.player().getStatistic().winLossRatio())); + lossWinRatio.setText(TextUtil.decimalFormat(Current.player().getStatistic().winLossRatio())); } if (eventMatchWins != null) { eventMatchWins.setText(String.valueOf(Current.player().getStatistic().eventWins()));