-1

我想要没有美元符号的钱输入框。有一个代码可以很好地处理美元

            private int price = 0;
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(!s.toString().matches("^\\$(\\d{1,3}(\\,\\d{3})*|(\\d+))(\\.\\d{2})?")) {
                    String userInput = "" + s.toString().replaceAll("[^\\d]", "");
                    if (userInput.length() > 2) {
                        Float in = Float.parseFloat(userInput);
                        price = Math.round(in); // just to get an Integer
                        //float percen = in/100;
                        String first, last;
                        first = userInput.substring(0, userInput.length() - 2);
                        last = userInput.substring(userInput.length() - 2);
                        inputAmount.setText("$" + first + "." + last);
                        Log.e(FragTutar.class.toString(), "first: " + first + " last:" + last);
                        inputAmount.setSelection(inputAmount.getText().length());
                    }
                }}
        });

我尝试了所有方法,但无法删除 $ sysmbol。如何删除此代码?

4

1 回答 1

0

请更改此行

inputAmount.setText("$" + first + "." + last);

对此

inputAmount.setText(first + "." + last);
于 2014-04-03T14:19:33.333 回答