Reputation: 553
I'm failing to understand why this will only return 0 or 100.
decimal TotalUptimePercent;
TotalUptimePercent = (uptime / (uptime + downtime)) * 100;
MessageBox.Show("Uptime: " + TotalUptimePercent.ToString());
I've tried using double instead of decimal but that didn't work either.
I did look over the site and found some other posts about percentages which recommended using decimal, but isn't working for me.
Upvotes: 0
Views: 115
Reputation: 32576
If uptime
and downtime
are int
or alike, try
double TotalUptimePercent = (uptime / (uptime + (double)downtime)) * 100;
See / Operator:
When you divide two integers, the result is always an integer. For example, the result of 7 / 3 is 2.
Upvotes: 7