diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java index 9fbe27dde9..9bbe5312d2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java @@ -528,10 +528,10 @@ public void run() { EnumChatFormatting moneyPrefix = money>50*1000*1000? (money>200*1000*1000?EnumChatFormatting.GREEN:EnumChatFormatting.YELLOW):EnumChatFormatting.RED; Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( - g+"Purse: "+moneyPrefix+Utils.shortNumberFormat(purseBalance, 0) + g+" - Bank: " + + g+"Purse: "+moneyPrefix+Utils.shortNumberFormat(purseBalance) + g+" - Bank: " + (bankBalance == -1 ? EnumChatFormatting.YELLOW+"N/A" : moneyPrefix+ - (isMe?"4.8b":Utils.shortNumberFormat(bankBalance, 0))) + - (networth > 0 ? g+" - Net: "+moneyPrefix+Utils.shortNumberFormat(networth, 0) : ""))); + (isMe?"4.8b":Utils.shortNumberFormat(bankBalance))) + + (networth > 0 ? g+" - Net: "+moneyPrefix+Utils.shortNumberFormat(networth, 2) : ""))); overallScore += Math.min(2, money/(100f*1000*1000)); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java index fc2eaf61e8..e6431b9345 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/AuctionBINWarning.java @@ -148,14 +148,14 @@ public void render() { String lowestPriceStr; if(lowestPrice > 999) { - lowestPriceStr = Utils.shortNumberFormat(lowestPrice, 0); + lowestPriceStr = Utils.shortNumberFormat(lowestPrice); } else { lowestPriceStr = ""+lowestPrice; } String sellingPriceStr; if(sellingPrice > 999) { - sellingPriceStr = Utils.shortNumberFormat(sellingPrice, 0); + sellingPriceStr = Utils.shortNumberFormat(sellingPrice); } else { sellingPriceStr = ""+sellingPrice; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java index aafcfb4d7c..7e193cbcd3 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DamageCommas.java @@ -67,7 +67,7 @@ public static IChatComponent replaceName(EntityLivingBase entity) { int number = Integer.parseInt(numbers); if(number > 999 && NotEnoughUpdates.INSTANCE.config.misc.damageIndicatorStyle == 2) { - newFormatted.append(Utils.shortNumberFormat(number, 0)); + newFormatted.append(Utils.shortNumberFormat(number, 2)); } else { newFormatted.append(NumberFormat.getIntegerInstance().format(number)); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 2992662825..d8881cc41a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -357,8 +357,8 @@ private List createStringsForPet(Pet currentPet, boolean secondPet) { roundFloat(currentPet.petLevel.currentLevelRequirement) + EnumChatFormatting.YELLOW + " (" + getLevelPercent(currentPet) + "%)"; - String lvlString = EnumChatFormatting.AQUA + "" + Utils.shortNumberFormat(levelXp, 0) + "/" + - Utils.shortNumberFormat(currentPet.petLevel.currentLevelRequirement, 0) + String lvlString = EnumChatFormatting.AQUA + "" + Utils.shortNumberFormat(levelXp) + "/" + + Utils.shortNumberFormat(currentPet.petLevel.currentLevelRequirement) + EnumChatFormatting.YELLOW + " (" + getLevelPercent(currentPet) + "%)"; float xpGain; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 7876776ba1..1657a884bc 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -255,15 +255,15 @@ public static String chromaString(String str, float offset, boolean bold) { return rainbowText.toString(); } - private static char[] c = new char[]{'k', 'm', 'b', 't'}; - public static String shortNumberFormat(double n, int iteration) { - double d = ((long) n / 100) / 10.0; - boolean isRound = (d * 10) %10 == 0; - return (d < 1000? - ((d > 99.9 || isRound || (!isRound && d > 9.99)? - (int) d * 10 / 10 : d + "" - ) + "" + c[iteration]) - : shortNumberFormat(d, iteration+1)); + private static char[] c = new char[]{'k', 'M', 'B', 't', 'q', 'Q', 's', 'S'}; + public static String shortNumberFormat(double n, int dp) { + int pow1k = (int) Math.floor(Math.log(n) / Math.log(1000)); + if (pow1k == 0 || pow1k > 8) {return String.valueOf(n);} + double mantissa = n / (Math.pow(1000, pow1k)); + return (String.format("%." + dp + "f", mantissa) + c[pow1k - 1]); + } + public static String shortNumberFormat(double n) { + return shortNumberFormat(n, 1); } public static String trimIgnoreColour(String str) {