1.First remark you should do some validation of the user input and also to manage the exception case, like goal that could have 0 value ==> division with 0 will generate exception. Also you should use
TryParse
and not
Parse
.
2.Then you should use
double
and not
int
in temp computation of the percent value like below:
double goal = 1;
bool ok = double.TryParse(GoalText.Text.Trim(), out goal);
if(!ok || goal <= 0.0)
{
}
double currentXp = 0.0;
ok = double.TryParse(CurrentText.Text.Trim(), out currrentXp);
if(!ok || currentXp < 0)
{
}
double percentage = 100.0*currentXp/goal;
4.Finally you could show in the UI as many decimals you want, or no decimals. For example for showing the percent with 2 decimals here is the code:
PercentageLabel.Text = string.Format("{0:#,0.00}", percentage);