Android String format - price

Viewed 37182

Is there an easy formatter to format my String as a price?

So my string is: 300000 i'd like to "300 000" with space

or 1000000 "1 000 000"

Leslie

5 Answers

if you have integer value, most elegant in my opinion

public static String formatNumberWithSpaces(long number) {
    DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance();
    DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
    symbols.setGroupingSeparator(' ');
    return formatter.format(number);
}
Related