开发者

How to code for the "." for the Use of decimal input?

I am developing the calculator for android. I have implemented all the functionality, Now just getting stop at the decimal value. I dont know how to implement that functionality on the click of custom "." button. I want decimal value up to two fraction point. can anybudy help me to develop such code? I nee开发者_如何学Pythond it. . . I know it seem very easy but right now i got stuck in that matter. Pleae help me in this Thanks in advance.


As it is, this is a very broad question. I recommend you to check this http://www.codeproject.com/KB/android/androidcalculator.aspx

Generally speaking, you need to:
1) Implement UI
2) Implement click handlers for the buttons
3) Implement evaluation function

If you get stuck at something particular ask it here and post your code.

EDIT:
There you can see how it is implemented, you can use similar logic:

    case DECIMAL_SEP: // Handle decimal seperator
        if (hasFinalResult || resetInput) { // if previous result is calculated or the input is reset, insert 0 before
            userInputText.setText("0.");
            hasFinalResult = false;
            resetInput = false;
        } else if (currentInput.contains(".")) // don't let 2nd '.'
            return;
        else
            userInputText.append("."); // append '.'
        break;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜