I'm got write a simple calculation. which only use % and / .but when i key in different number. the result is different.Who can help me.

private void button1_Click(object sender, EventArgs e)
        {
            
            decimal x = txtPer.Value;
            decimal y = txtQty.Value;

            decimal j= y / x;
            decimal k = y % x;
            

                txtPack.Value = j;
                txtRemain.Value = k;
            

        }

From the picture, we can see that 10/3=3 and 10%3=1 is right.
But I key in 5/2=3 5%2=1 is wrong. It should be 5/2=2.
If 5/2=3 5%2=1,we multiply and plus back will become 2*3+1=7. The answer is wrong

I'm got write a simple calculation. which only use % and / .but when i key in different number. the result is different.Who can help me.

private void button1_Click(object sender, EventArgs e)
        {
            
            decimal x = txtPer.Value;
            decimal y = txtQty.Value;

            decimal j= y / x;
            decimal k = y % x;
            

                txtPack.Value = j;
                txtRemain.Value = k;
            

        }

From the picture, we can see that 10/3=3 and 10%3=1 is right.
But I key in 5/2=3 5%2=1 is wrong. It should be 5/2=2.
If 5/2=3 5%2=1,we multiply and plus back will become 2*3+1=7. The answer is wrong

I'm already solve problem. Just convert from decimal to int.
for example, int a = Convert.ToInt32(txtQty.Value);
this is work.

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.