您好朋友我正在使用以下代码以货币形式显示输入的金额。
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]", "");
StringBuilder cashAmountBuilder = new StringBuilder(userInput);
while (cashAmountBuilder.length() > 3 && cashAmountBuilder.charAt(0) == '0') {
cashAmountBuilder.deleteCharAt(0);
}
while (cashAmountBuilder.length() < 3) {
cashAmountBuilder.insert(0, '0');
}
cashAmountBuilder.insert(cashAmountBuilder.length()-2, '.');
cashAmountBuilder.insert(0, '$');
editAmount.setText(cashAmountBuilder.toString());
editAmount.setTextKeepState(cashAmountBuilder.toString());
Selection.setSelection(editAmount.getText(), cashAmountBuilder.toString().length());
}
}
该符号以“$”为前缀的问题我希望将其替换为新的 INR 符号或空白。我尝试用cashAmountBuilder.insert(0, '$');
空白替换代码补丁,它给了我编译器错误。请同样帮助我。谢谢,