Hey there, so im making a calculator to make my life a little bit easier ^^
so far its working well, I just got one problem o.O! If I enter a number with a comma like 0,5 into one of the textboxes and click calculate it will terminate, what can i do to fix this :)?

private void button2_Click(object sender, EventArgs e)
        {
            
                int number1;
                int number2;
                
                float answer;
                number1 = int.Parse(textBox4.Text);
                number2 = int.Parse(textBox5.Text);
                answer = number1 + number2;
                textBox7.Text = answer.ToString();
                textBox8.Text = answer.ToString();
            
        }

kind regards -Jazerix

Edit: ive tried inserting 0.5 and ½ instead, still doesn't work :(

The integer type only takes whole numbers.
If you want real type numbers with a comma, you have to use the float or double types instead of int, to do your calculations.

ddanbe has the nail on the head there.

You are parsing text into integers. Any value other than a whole number (no commas) will be unable to be parsed in such a way and will terminate the process.

As a note, comma notation for numerals is not a computational or mathematical representation but a visual addition that, in fact, is rarely in common use any longer. The system doesn't understand 120,000 but would understand 120000. You would need to go into much more depth with your parsing if you want it to be able to handle comma-notation in your input.

Small addition:
In my country, the comma is the decimal separator.
In other counrtries it is the point.

Small addition:
In my country, the comma is the decimal separator.
In other counrtries it is the point.

Good point :) My statement was more towards the way the program looks at it however.

Int = whole numeral = no denomination of decimal or comma

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.