I've created my own formatting utility. Which is extremely fast at processing the formatting along with giving you many features :)
It supports:
- Comma Formatting E.g. 1234567 becomes 1,234,567.
- Prefixing with "Thousand(K),Million(M),Billion(B),Trillion(T)".
- Precision of 0 through 15.
- Precision re-sizing (Means if you want 6 digit precision, but only have 3 available digits it forces it to 3).
- Prefix lowering (Means if the prefix you choose is too large it lowers it to a more suitable prefix).
The code can be found here. You call it like this:
public static void main(String[])
{
int settings = ValueFormat.COMMAS | ValueFormat.PRECISION(2) | ValueFormat.MILLIONS;
String formatted = ValueFormat.format(1234567, settings);
}
I should also point out this doesn't handle decimal support, but is very useful for integer values. The above example would show "1.23M" as the output. I could probably add decimal support maybe, but didn't see too much use for it since then I might as well merge this into a BigInteger type of class that handles compressed char[] arrays for math computations.