public class NumberToReadableWordFormat {
public static void main(String[] args) {
Integer[] numbers = new Integer[]{1000, 5821, 10500, 101800, 2000000, 7800000, 92150000, 123200000, 9999999,999};
for(int n : numbers) {
System.out.println(n + " => " + coolFormat(n));
}
}
private static String[] c = new String[]{"K", "L", "Cr"};
private static String coolFormat(int n) {
int size = String.valueOf(n).length();
if (size>=4 && size<6) {
int value = (int) Math.pow(10, 1);
double d = (double) Math.round(n/1000.0 * value) / value;
return (double) Math.round(n/1000.0 * value) / value+" "+c[0];
} else if(size>5 && size<8) {
int value = (int) Math.pow(10, 1);
return (double) Math.round(n/100000.0 * value) / value+" "+c[1];
} else if(size>=8) {
int value = (int) Math.pow(10, 1);
return (double) Math.round(n/10000000.0 * value) / value+" "+c[2];
} else {
return n+"";
}
}
}
Выход:
1000 => 1.0 K
5821 => 5.8 K
10500 => 10.5 K
101800 => 1.0 L
2000000 => 20.0 L
7800000 => 78.0 L
92150000 => 9.2 Cr
123200000 => 12.3 Cr
9999999 => 100.0 L
999 => 999