I have custom DecimalFormat in Edittext\'s addTextChangedListener method, everything is working perfectly but when I change language (locale) my addTextChanged
You can specify the number of fraction digit after the decimal point, and/or the numbers before the decimal point. Of-course, setting the current locale is also important.
private String formatNumber(double number) {
NumberFormat nf = NumberFormat.getNumberInstance(Locale.getDefault());
if (nf instanceof DecimalFormat) {
try {
DecimalFormat formatter = (DecimalFormat) nf;
formatter.setDecimalSeparatorAlwaysShown(true);
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
return formatter.format(new BigDecimal(number);
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
}
}
return null;
}