From d4b8c67c9a8dec5f4f84f6385052e584d9cdcc01 Mon Sep 17 00:00:00 2001 From: Futuremappermydud <54294576+Futuremappermydud@users.noreply.github.com> Date: Mon, 11 Jul 2022 08:45:05 -0400 Subject: SignCalculator use decimal points in rendered text (#182) * SignCalculator use decimal points in rendered text this was really bugging me * Update /neucalc --- .../moulberry/notenoughupdates/commands/misc/CalculatorCommand.java | 5 ++++- .../io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/main') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java index e73e3b32..05e2087d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/misc/CalculatorCommand.java @@ -26,6 +26,7 @@ import net.minecraft.command.ICommandSender; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; +import java.text.DecimalFormat; import java.math.BigDecimal; import java.util.Arrays; import java.util.List; @@ -55,9 +56,11 @@ public class CalculatorCommand extends ClientCommandBase { String source = String.join(" ", args); try { BigDecimal calculate = Calculator.calculate(source); + DecimalFormat formatter = new DecimalFormat("#,###.00"); + String lr = formatter.format(calculate); sender.addChatMessage(new ChatComponentText( EnumChatFormatting.YELLOW + "[NEU] " + EnumChatFormatting.WHITE + source + " = " + EnumChatFormatting.GREEN + - calculate.toPlainString() + lr )); } catch (Calculator.CalculatorException e) { sender.addChatMessage(new ChatComponentText( diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java index 115458c9..f3d4237d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/SignCalculator.java @@ -31,6 +31,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import java.text.DecimalFormat; import java.math.BigDecimal; import java.util.Objects; @@ -76,7 +77,8 @@ public class SignCalculator { public String getRenderedString() { if (lastResult != null) { - String lr = lastResult.toPlainString(); + DecimalFormat formatter = new DecimalFormat("#,###.00"); + String lr = formatter.format(lastResult); if (Minecraft.getMinecraft().fontRendererObj.getStringWidth(lr) > 90) { return EnumChatFormatting.WHITE + lastSource + " = " + EnumChatFormatting.RED + "Result too long"; } -- cgit