Hell guys,
i am using following code to input currency in editText 3
amount.addTextChangedListener(new CurrencyTextWatcher());
public class CurrencyTextWatcher implements TextWatcher {
boolean mEditing;
public CurrencyTextWatcher() {
mEditing = false;
}
public synchronized void afterTextChanged(Editable s) {
if(!mEditing) {
mEditing = true;
String digits = s.toString().replaceAll("\\D", "");
NumberFormat nf = NumberFormat.getCurrencyInstance();
try{
String formatted = nf.format(Double.parseDouble(digits)/100);
s.replace(0, s.length(), formatted);
} catch (NumberFormatException nfe) {
s.clear();
}
mEditing = false;
}
}
The problem with this code is, it start taking input from the right hand side
E.g first-- 0.01 --> 0.12 --> 1.21 and so on. I want to do this in usual way.
E.g when i had 1 it shows as 1.00 thehn 12.00 then when i press decimal no. it should give me 12.10 etc
Please tell me how can i edit my code. Best Regards
No comments:
Post a Comment