Start New Discussion within our Software Development Community

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!

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());
                    case "%":
                        _NUMBER = _ACCUMULATOR * _NUMBER / 100;
                        this.DisplayTxB.Text = AdjustDisplayString(_ACCUMULATOR.ToString());
                        _NUMBER = 0.0;
                        _NewNumber = true;
                    case "1/x":
                        _NUMBER = Convert.ToDouble(this.DisplayTxB.Text);
                        if (_NUMBER != 0.0) _NUMBER = 1 / _NUMBER;
                        this.DisplayTxB.Text = AdjustDisplayString(_NUMBER.ToString());                    
        } //END FunctionBtn_Click


This article has been dead for over six months. Start a new discussion instead.