Merge pull request #12460 from Isira-Seneviratne/Short-count-refactor

Fix short count formatting for Android versions below 7.0
This commit is contained in:
Tobi 2025-08-01 10:56:41 -07:00 committed by GitHub
commit ff3526b28d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
79 changed files with 18 additions and 238 deletions

View file

@ -190,14 +190,20 @@ public final class Localization {
final double value = (double) count;
if (count >= 1000000000) {
return localizeNumber(round(value / 1000000000))
+ context.getString(R.string.short_billion);
final double shortenedValue = value / 1000000000;
final int scale = shortenedValue >= 100 ? 0 : 1;
return context.getString(R.string.short_billion,
localizeNumber(round(shortenedValue, scale)));
} else if (count >= 1000000) {
return localizeNumber(round(value / 1000000))
+ context.getString(R.string.short_million);
final double shortenedValue = value / 1000000;
final int scale = shortenedValue >= 100 ? 0 : 1;
return context.getString(R.string.short_million,
localizeNumber(round(shortenedValue, scale)));
} else if (count >= 1000) {
return localizeNumber(round(value / 1000))
+ context.getString(R.string.short_thousand);
final double shortenedValue = value / 1000;
final int scale = shortenedValue >= 100 ? 0 : 1;
return context.getString(R.string.short_thousand,
localizeNumber(round(shortenedValue, scale)));
} else {
return localizeNumber(value);
}
@ -416,8 +422,8 @@ public final class Localization {
}
}
private static double round(final double value) {
return new BigDecimal(value).setScale(1, RoundingMode.HALF_UP).doubleValue();
private static double round(final double value, final int scale) {
return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue();
}
private static String getQuantity(@NonNull final Context context,