Android: simple format input number -


this question has answer here:

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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -