It is necessary to format the currency for TextView

i 1515.2777777777778parse the json object and suppose I have this value I need to parse the currency like this:
€ 1'515,27

Is there a special class that can directly convert? or should I do it like this:

Double number = Double.valueOf(obj.getString("price"));
DecimalFormat decimalFormat = new DecimalFormat("€ #\\'###.00");
String prezzo = decimalFormat.format(number);

but even so, I t is not the only apostrophe.

+4
source share
2 answers

The format in which you need € #,###.00, ,means that you are using the grouping separator.

You will then need DecimalFormatSymbolsto specify the grouping symbol and decimal character:

DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setGroupingSeparator('\'');
symbols.setDecimalSeparator(',');

DecimalFormat decimalFormat = new DecimalFormat("€ #,###.00", symbols);
String prezzo = decimalFormat.format(number);

Result € 1'515,28

+5

NumberFormat.getCurrencyInstance() NumberFormat.getCurrencyInstance(Locale locale), NumberFormat, .

+6

All Articles