- Joined
- Aug 5, 2014
- Messages
- 3,212
- Thread Author
- #1
Code:
public static String format(long i) {
String formatted = "";
String end = "";
NumberFormat format = NumberFormat.getInstance();
formatted = format.format(i).toString();
if (i >= 1000) {
end = "k";
if (i >= 1000000) {
end = "M";
if (i >= 1000000000) {
end = "B";
}
}
formatted = formatted.split("\\.")[0] + "." + formatted.split("\\.")[1].substring(0, 2) + end;
}
return formatted;
}
Gist:
NewFormat.java · GitHub
Examples:
Code:
1.00k <--- 1000
11.92k <--- 11,929
158.39k <--- 158,390
999.99k <--- 999,999
1.00M <--- 1,000,001
12.34B <--- 12,345,678,912
Last edited: