1

I always get 0 for percentage when I do this:

int trackBarValue = trackBar.Value;
float percentage = trackBarValue / 100;

What's wrong with my code?

Cyclonecode
  • 29,115
  • 11
  • 72
  • 93
user310291
  • 36,946
  • 82
  • 271
  • 487

1 Answers1

3

The problem is you're doing an integer division, which is truncated. Try this:

  int trackBarValue = trackBar.Value;
  float percentage = trackBarValue / 100.0;

This will do a floating point division, and given you the result you want.

Andrew Cooper
  • 32,176
  • 5
  • 81
  • 116