Android: simple format input number -
this question has answer here:
- edittext currency format 2 answers
i'm learning android. have edittext input money, , if enter input number 1000, result must 1.000, , if enter input 1000000, result must 1.000.000.
while i'm typing, every 3 characters last beginning must have ".".
you can use inputfilter
public class currencyformat implements inputfilter { pattern mpattern = pattern.compile("(0|[1-9]+[0-9]*)?(\\.[0-9]{0,2})?"); @override public charsequence filter(charsequence source, int start, int end, spanned dest, int dstart, int dend) { string result = dest.subsequence(0, dstart) + source.tostring() + dest.subsequence(dend, dest.length()); matcher matcher = mpattern.matcher(result); if (!matcher.matches()) return dest.subsequence(dstart, dend); return null; } }
you can set filters like:
edittext.setfilters(new inputfilter[] {new currencyformat()});
accept it, if find useful.
Comments
Post a Comment