英文:
Delete problem with double at Calculator App at android studio?
问题
btnclear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value1 = Double.parseDouble(edttext.getText() + "");
String s = Value1 + "";
String Res = "";
for (int i = 0; i < s.length() - 1; i++) {
Res += s.charAt(i);
}
if (Res.equals(""))
edttext.setText("0");
else
edttext.setText(null);
edttext.setText(Res);
}
});
英文:
I am trying make a calculator app in Android Studio. But i cant fix delete function problem. If the number is decimal,it can not deletes before the decimal comma. For example my number is (12,12). Delete button is first deleting last number, so new number is (12.1.). And later (12.) And later (12.). It is cant be (12) or (1). How can i fix ?
btnclear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value1 = Double.parseDouble(edttext.getText() + "");
String s = Value1 + "";
String Res = "";
for (int i = 0; i < s.length() - 1; i++) {
Res += s.charAt(i);
}
if (Res.equals(""))
edttext.setText("0");
else
edttext.setText(null);
edttext.setText(Res);
}
});
专注分享java语言的经验与见解,让所有开发者获益!
评论