Progress Bar - How to take decimal values?

Asked

Viewed 394 times

0

By learning, I am creating a very stupid "game" in C# and I make a bar the bar of life, but I need to decrease a decimal value and apparently the Progress only takes int values. How can I get her to present decimal values like 99.2%?

The Progress bar is defined naturally with a minimum of 0 and a maximum of 100. Line that makes the decrease in life:

lifeP1.Value -= (int)(ataque2);
  • No, you can’t change the type of the control variable. If it is necessary to increase the accuracy, you can increase the limit ex: 1000 and when displaying the information take the value and divide: labelVida.Text = (progressBar1.Value / 1000d).ToString("P1"); outworking: 99.2 %.

1 answer

1


You can set the value of the Maximum property of Progressbar to a higher value and multiply. For example you set the Maximum to 1000 and at the time of setting the value you can put 99.2 * 10 = 992, still inside the range;

  • I understand. In case, some practical means to simply force . Value of the bar to be double there is, right?

  • No, there is, the simplest way is this same, another colleague put a comment, giving another idea how to do this account, but will always have to make this conversion.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.