Skip to content

Commit

Permalink
Use Number Suffix for Economy Wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
gmitch215 committed Sep 16, 2023
1 parent d99ed93 commit 95ccf02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,16 @@ public static String capitalize(@NotNull String str) {
return sb.toString().trim();
}

private static final char[] SUFFIXES = "KMBTQEXSON".toCharArray();

public static String withSuffix(double num) {
if (num < 0) return "-" + withSuffix(-num);
if (num < 1000) return format("%,.2f", num);

int index = (int) (Math.log10(num) / 3);
String suffix = SUFFIXES[index - 1] + "";

return format("%.2f%s", num / Math.pow(1000, index), suffix);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static us.teaminceptus.novaconomy.abstraction.Wrapper.get;
import static us.teaminceptus.novaconomy.abstraction.Wrapper.w;
import static us.teaminceptus.novaconomy.util.NovaUtil.format;
import static us.teaminceptus.novaconomy.util.NovaUtil.withSuffix;

public final class Items {

Expand Down Expand Up @@ -251,7 +252,7 @@ public static ItemStack economyWheel(String suffix, Economy econ, OfflinePlayer
meta -> {
meta.setDisplayName(ChatColor.GOLD + econ.getName());
meta.setLore(Collections.singletonList(
format(ChatColor.AQUA + get("constants.balance"), ChatColor.YELLOW + format("%,.2f", np.getBalance(econ)) + econ.getSymbol())
format(ChatColor.AQUA + get("constants.balance"), ChatColor.YELLOW + withSuffix(np.getBalance(econ)) + " (" + econ.getSymbol() + ")")
));
},
nbt -> {
Expand Down

0 comments on commit 95ccf02

Please sign in to comment.