我想没有美元符号的钱输入框。有一个代码可以很好地与美元
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());
}
}}
});
我尝试了所有方法,我无法删除$符号。如何删除此代码?
答案 0 :(得分:0)
请更改此行
inputAmount.setText("$" + first + "." + last);
到这个
inputAmount.setText(first + "." + last);