I'd like to format following numbers into the numbers next to them with Android:
1000 to 1k 5821 to 5.8k 2000000 to 2m 7800000 to 7.8m
This should do the trick
String numberString = "";
if (Math.abs(number / 1000000) > 1) {
numberString = (number / 1000000).toString() + "m";
} else if (Math.abs(number / 1000) > 1) {
numberString = (number / 1000).toString() + "k";
} else {
numberString = number.toString();
}