making EditText to show only two decimal places

前端 未结 4 983
礼貌的吻别
礼貌的吻别 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:38

    You can simply use DecimalFormat

    DecimalFormat format = new DecimalFormat("##.##");
    String formatted = format.format(22.123);
    editText.setText(formatted);
    

    You will get result in EditText as 22.12

提交回复
热议问题