1,105,312 Community Members

C# percent calculator

Member Avatar
Siimont
Newbie Poster
2 posts since Apr 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello!
I'm doing a calculator in c# and I have one problem.
I can't get the "%" button to work. I want it to work just like microsofts calculator and it would be great if annyone could help me! :)

Its the code for how to calculate it I need!

Member Avatar
ddanbe
Posting Expert
5,335 posts since Oct 2008
Reputation Points: 2,054 [?]
Q&As Helped to Solve: 904 [?]
Skill Endorsements: 46 [?]
Featured
 
2
 

Hi Siimont, welcome on the daniweb site.
Have a look at this thread, in one of the posts it has a zip file with some code for a calculator. It is a simulation of a calculator I have at home.
It acts differently than the MS one but if you look at the code it must be somehow possible to convert this into the action an MS calculator does in case of a percentage calculation.
This is a piece of my code that handles the "function" buttons on my calculator, for further details look in the zip file, or ask a question.

private void FunctionBtn_Click(object sender, EventArgs e)
        {
            if (_CalculatorON)
            {
                Button FunctionBtn = sender as Button;

                switch (FunctionBtn.Text)
                {
                    case "sqrt":
                        _NUMBER = Math.Sqrt(Convert.ToDouble(this.DisplayTxB.Text));
                        this.DisplayTxB.Text = AdjustDisplayString(_NUMBER.ToString());
                        break;
                    case "%":
                        _NUMBER = _ACCUMULATOR * _NUMBER / 100;
                        Calculate();
                        this.DisplayTxB.Text = AdjustDisplayString(_ACCUMULATOR.ToString());
                        _NUMBER = 0.0;
                        _NewNumber = true;
                        break;
                    case "1/x":
                        _NUMBER = Convert.ToDouble(this.DisplayTxB.Text);
                        if (_NUMBER != 0.0) _NUMBER = 1 / _NUMBER;
                        this.DisplayTxB.Text = AdjustDisplayString(_NUMBER.ToString());                    
                        break;
                    default:
                        break;
                }
            }
        } //END FunctionBtn_Click

Succes!

Member Avatar
Siimont
Newbie Poster
2 posts since Apr 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank you so much ddanbe!
This solved my problem :D

Member Avatar
aadisabri
Newbie Poster
1 post since Oct 2011
Reputation Points: -2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

u want code for percentage calculator in adding of function C# so you can go first the application in calculator then change inner value's of the digit.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: