move decimal format to TextUtil

This commit is contained in:
Anthony Calosa
2023-07-09 10:48:34 +08:00
parent f757192df5
commit 3ec52cae4b
2 changed files with 6 additions and 5 deletions

View File

@@ -42,6 +42,10 @@ public class TextUtil {
return Normalizer.normalize(text, Normalizer.Form.NFD); 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. * Safely converts an object to a String.
* *

View File

@@ -32,9 +32,9 @@ import forge.localinstance.achievements.CardActivationAchievements;
import forge.localinstance.achievements.PlaneswalkerAchievements; import forge.localinstance.achievements.PlaneswalkerAchievements;
import forge.model.FModel; import forge.model.FModel;
import forge.player.GamePlayerUtil; import forge.player.GamePlayerUtil;
import forge.util.TextUtil;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import java.text.DecimalFormat;
import java.util.Map; import java.util.Map;
public class PlayerStatisticScene extends UIScene { public class PlayerStatisticScene extends UIScene {
@@ -53,7 +53,6 @@ public class PlayerStatisticScene extends UIScene {
boolean toggle = false; boolean toggle = false;
AchievementCollection planeswalkers, achievements, cardActivation; AchievementCollection planeswalkers, achievements, cardActivation;
Scene lastGameScene; Scene lastGameScene;
DecimalFormat df;
private PlayerStatisticScene() { private PlayerStatisticScene() {
super(Forge.isLandscapeMode() ? "ui/statistic.json" : "ui/statistic_portrait.json"); 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())); totalLoss.setText(String.valueOf(Current.player().getStatistic().totalLoss()));
} }
if (lossWinRatio != null) { if (lossWinRatio != null) {
if (df == null) lossWinRatio.setText(TextUtil.decimalFormat(Current.player().getStatistic().winLossRatio()));
df = new DecimalFormat("#.##");
lossWinRatio.setText(df.format(Current.player().getStatistic().winLossRatio()));
} }
if (eventMatchWins != null) { if (eventMatchWins != null) {
eventMatchWins.setText(String.valueOf(Current.player().getStatistic().eventWins())); eventMatchWins.setText(String.valueOf(Current.player().getStatistic().eventWins()));