-7

I am trying to get a value of trackbar / slider, divide it by 100 and display the value in label.

I get an error Operator '/' cannot be applied to operands of type 'int' and 'string'.

Here's my try:

private void siticoneTrackBar1_Scroll(object sender, ScrollEventArgs e)
{
    label6.Text = siticoneTrackBar1.Value / 100.ToString();
}

Can anyone help?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Ondřej
  • 11
  • 1

1 Answers1

3

The problem is operator precedence here: you're trying to divide the value of siticoneTrackBar1.Value by the result of calling 100.ToString(). Instead, I strongly suspect you intended to perform the division of the two numbers, then call ToString on the result. The "dot" operator has higher precedence than division, so you need to use brackets to tell the compiler what to do:

private void siticoneTrackBar1_Scroll(object sender, ScrollEventArgs e)
{
    label6.Text = (siticoneTrackBar1.Value / 100).ToString();
}
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194