1.11M Members

C# percent calculator

 
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!

 
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!

 
0
 

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

 
-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 six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: