1

I have following code

float m = vScrollBar1.Value;
float a = (100 - m);
textBox1.Text = a.ToString();

   float b = (a - 32);
   float c = (5 / 9);
   b = b * c;
   textBox2.Text = b.ToString();

when I scroll the scrollbar, value of textbox1 change gradually but textbox2 value always show zero. I used double also and still get show zero always. Someone please help me out here. Thanks in advance.

1
  • 2
    This is an often asked question. 5 / 9 is 0. You are performing integer math. Use 5f / 9f as a starter and see where it gets you. Commented Mar 24, 2013 at 18:14

1 Answer 1

2

Because (5 / 9) is integer division.

Try (5.0f / 9) instead.

Sign up to request clarification or add additional context in comments.

1 Comment

or you can also use just 5f, just shorter a little bit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.