在Android Studio中的计算器应用中删除双倍问题?

huangapple 未分类评论41阅读模式
英文:

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() + &quot;&quot;);
            String s = Value1 + &quot;&quot;;
            String Res = &quot;&quot;;
            for (int i = 0; i &lt; s.length() - 1; i++) {
                Res += s.charAt(i);
            }
            if (Res.equals(&quot;&quot;))
                edttext.setText(&quot;0&quot;);
            else
                edttext.setText(null);
            edttext.setText(Res);
        }
    });

huangapple
  • 本文由 发表于 2020年5月19日 20:41:16
  • 转载请务必保留本文链接:https://java.coder-hub.com/61891290.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定