javansnumberformatter

NumberFormat.format is also formatting digits as per locale


NumberFormat.format is changing 1000Rs to ₹ ১,০০০.০০ which are actually digits in Bangla language, similar thing is happening for IQD there it is getting changed in Iraqi language digit. How can we format by keeping digits in 1-9 only and get only formatting for separator and decimal point as per locale

NumberFormat amountFormatter = NumberFormat.getCurrencyInstance(
                Locale.getdefault());
String formattedAmount = amountFormatter.format(Double.parseDouble(actualAmount))

Solution

  • I found solution. We can get DecimalFormatSymbols instance and set Zerodigit character to avoid other digits symbol

    DecimalFormatSymbols decimalFormatSymbols = ((DecimalFormat) numberFormat).getDecimalFormatSymbols();
                decimalFormatSymbols.setZeroDigit('0');