2626import java .util .List ;
2727import java .util .Locale ;
2828
29+ import static org .schabi .newpipe .util .Utils .round ;
30+
2931/*
3032 * Created by chschtsch on 12/29/15.
3133 *
@@ -110,7 +112,7 @@ public static Locale getPreferredLocale(Context context) {
110112 if (languageCode .length () == 2 ) {
111113 return new Locale (languageCode );
112114 } else if (languageCode .contains ("_" )) {
113- String country = languageCode .substring (languageCode .indexOf ("_" ), languageCode . length () );
115+ String country = languageCode .substring (languageCode .indexOf ("_" ));
114116 return new Locale (languageCode .substring (0 , 2 ), country );
115117 }
116118 } catch (Exception ignored ) {
@@ -120,6 +122,10 @@ public static Locale getPreferredLocale(Context context) {
120122 }
121123
122124 public static String localizeNumber (Context context , long number ) {
125+ return localizeNumber (context , (double ) number );
126+ }
127+
128+ public static String localizeNumber (Context context , double number ) {
123129 NumberFormat nf = NumberFormat .getInstance (getAppLocale (context ));
124130 return nf .format (number );
125131 }
@@ -146,14 +152,15 @@ public static String localizeWatchingCount(Context context, long watchingCount)
146152 }
147153
148154 public static String shortCount (Context context , long count ) {
155+ double value = (double ) count ;
149156 if (count >= 1000000000 ) {
150- return Long . toString ( count / 1000000000 ) + context .getString (R .string .short_billion );
157+ return localizeNumber ( context , round ( value / 1000000000 , 1 ) ) + context .getString (R .string .short_billion );
151158 } else if (count >= 1000000 ) {
152- return Long . toString ( count / 1000000 ) + context .getString (R .string .short_million );
159+ return localizeNumber ( context , round ( value / 1000000 , 1 ) ) + context .getString (R .string .short_million );
153160 } else if (count >= 1000 ) {
154- return Long . toString ( count / 1000 ) + context .getString (R .string .short_thousand );
161+ return localizeNumber ( context , round ( value / 1000 , 1 ) ) + context .getString (R .string .short_thousand );
155162 } else {
156- return Long . toString ( count );
163+ return localizeNumber ( context , value );
157164 }
158165 }
159166
0 commit comments