Hello Friends I am using the following code to show the amount entered in form of currency.
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(!s.toString().matches("^\\$(\\d{1,3}(\\,\\d{3})*|(\\d+))(\\.\\d{2})?$"))
{
String userInput= ""+s.toString().replaceAll("[^\\d]", "");
StringBuilder cashAmountBuilder = new StringBuilder(userInput);
while (cashAmountBuilder.length() > 3 && cashAmountBuilder.charAt(0) == '0') {
cashAmountBuilder.deleteCharAt(0);
}
while (cashAmountBuilder.length() < 3) {
cashAmountBuilder.insert(0, '0');
}
cashAmountBuilder.insert(cashAmountBuilder.length()-2, '.');
cashAmountBuilder.insert(0, '$');
editAmount.setText(cashAmountBuilder.toString());
editAmount.setTextKeepState(cashAmountBuilder.toString());
Selection.setSelection(editAmount.getText(), cashAmountBuilder.toString().length());
}
}
The issue the symbol has been prefixed with “$” I either want that to be replaced by new INR symbol or blank. I have tried replacing cashAmountBuilder.insert(0, '$'); patch of code with blank it gives me compiler error.Please help me in same.
Thanks,
Guys found the solution for this one.Would like to share the same with you all.