Skip to content

Commit

Permalink
fix: šŸ› Fix abbreviated count of stack in slot to always use fixed locā€¦
Browse files Browse the repository at this point in the history
ā€¦ale and not display broken characters with some locales
  • Loading branch information
P3pp3rF1y committed Dec 30, 2023
1 parent 9ff4a39 commit dcb1429
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false

mod_id=sophisticatedcore
mod_group_id=sophisticatedcore
mod_version=0.5.113
mod_version=0.5.114
sonar_project_key=sophisticatedcore:SophisticatedCore
github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedCore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

public class CountAbbreviator {
private CountAbbreviator() {}

private static final String[] COUNT_SUFFIXES = new String[] {"k", "m", "b"};
private static final DecimalFormatSymbols ROOT_LOCALE_FORMAT_SYMBOLS = new DecimalFormatSymbols(Locale.ROOT);
private static final DecimalFormat TWO_DIGIT_PRECISION;
private static final DecimalFormat ONE_DIGIT_PRECISION;

static {
TWO_DIGIT_PRECISION = new DecimalFormat("#.00");
TWO_DIGIT_PRECISION = new DecimalFormat("#.00", ROOT_LOCALE_FORMAT_SYMBOLS);
TWO_DIGIT_PRECISION.setRoundingMode(RoundingMode.DOWN);
ONE_DIGIT_PRECISION = new DecimalFormat("##.0");
ONE_DIGIT_PRECISION = new DecimalFormat("##.0", ROOT_LOCALE_FORMAT_SYMBOLS);
ONE_DIGIT_PRECISION.setRoundingMode(RoundingMode.DOWN);
}

Expand All @@ -25,7 +28,7 @@ public static String abbreviate(int count) {
public static String abbreviate(int count, int maxCharacters) {
int digits = (int) Math.log10(count) + 1;
if (digits <= maxCharacters) {
return String.format("%,d", count);
return String.format(Locale.ROOT, "%,d", count);
}

int thousandsExponent = ((digits - maxCharacters) / 3) + 1;
Expand All @@ -38,7 +41,7 @@ public static String abbreviate(int count, int maxCharacters) {

String numberPart = "";
if (wholeDigits > 3 || precisionDigits == 0) {
numberPart = String.format("%,d", (int) divisionResult);
numberPart = String.format(Locale.ROOT, "%,d", (int) divisionResult);
} else if (precisionDigits == 2) {
numberPart = TWO_DIGIT_PRECISION.format(divisionResult);
} else if (precisionDigits == 1) {
Expand Down

0 comments on commit dcb1429

Please sign in to comment.