Skip to content

Commit 9f11db8

Browse files
Improve scale display
1 parent 9f526e8 commit 9f11db8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

app/src/main/java/org/schabi/newpipe/util/Localization.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,20 @@ public static String shortCount(@NonNull final Context context, final long count
191191

192192
final double value = (double) count;
193193
if (count >= 1000000000) {
194+
final double shortenedValue = value / 1000000000;
195+
final int scale = shortenedValue >= 100 ? 0 : 1;
194196
return context.getString(R.string.short_billion,
195-
localizeNumber(round(value / 1000000000)));
197+
localizeNumber(round(shortenedValue, scale)));
196198
} else if (count >= 1000000) {
199+
final double shortenedValue = value / 1000000;
200+
final int scale = shortenedValue >= 100 ? 0 : 1;
197201
return context.getString(R.string.short_million,
198-
localizeNumber(round(value / 1000000)));
202+
localizeNumber(round(shortenedValue, scale)));
199203
} else if (count >= 1000) {
204+
final double shortenedValue = value / 1000;
205+
final int scale = shortenedValue >= 100 ? 0 : 1;
200206
return context.getString(R.string.short_thousand,
201-
localizeNumber(round(value / 1000, 0)));
207+
localizeNumber(round(shortenedValue, scale)));
202208
} else {
203209
return localizeNumber(value);
204210
}
@@ -416,10 +422,6 @@ private static Locale getLocaleFromPrefs(@NonNull final Context context,
416422
}
417423
}
418424

419-
private static double round(final double value) {
420-
return round(value, 1);
421-
}
422-
423425
private static double round(final double value, final int scale) {
424426
return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue();
425427
}

0 commit comments

Comments
 (0)