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:
commit
ff3526b28d
79 changed files with 18 additions and 238 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue