making EditText to show only two decimal places

前端 未结 4 985
礼貌的吻别
礼貌的吻别 2021-01-12 12:28

i want to show only two decimal places in my edit text, ofc i wanna show currency in edit text but limiting its value to 2 digits after decimal.

I have seen some sol

4条回答
  •  孤街浪徒
    2021-01-12 12:39

    You just need to assign setKeyListener() to your EditText.

    myEditText.setKeyListener(DigitsKeyListener.getInstance(true,true));
    

    Returns a DigitsKeyListener that accepts the digits 0 through 9, plus the minus sign (only at the beginning) and/or decimal point (only one per field) if specified.

提交回复
热议问题