java - Format Price in 0.00 format in android using edittext -
i trying mask price value in 0.00
format. here code
float temp = 0; decimalformat mdecimalformat = new decimalformat("###.00"); @override public void ontextchanged(charsequence s, int start, int before, int count) { if(s.tostring()!=null) { mmasedittext.removetextchangedlistener(this); temp = float.parsefloat(s.tostring()); mmasedittext.settext(""+mdecimalformat.format(addnumber(temp))); mmasedittext.setselection(start+1); mmasedittext.addtextchangedlistener(this); } } public float addnumber(float numtemp){ float result=0.00f; result = numtemp + result; return result; }
but when pressing decimal, want cursor go 1 more step. not able dot callback. when pressing button, remove digits, index out of bound exception. can tell me how button , dot button callback before ontextchanged listener?
recommended way of formatting currency , prices:
locale loc = locale.getdefault(); numberformat nf = numberformat.getcurrencyinstance(loc); nf.setcurrency(currency.getinstance(loc)); nf.setmaximumfractiondigits(2); nf.setminimumfractiondigits(2); system.out.println(nf.format(23.5634)); system.out.println(nf.format(0.5));
Comments
Post a Comment