public static FormatPercentage ( int value, int total, int places ) : String | ||
value | int | Value for which a percentage is needed. |
total | int | Total of all values from which to generate a percentage /// (divided by "value" parameter). |
places | int | Number of decimal places to return in the percentage string. |
return | String |
public static String FormatPercentage(int value, int total, int places)
{
Decimal percent = 0;
string retval = string.Empty;
String strplaces = new String('0', places);
if(value == 0 || total == 0)
{
percent = 0;
}
else
{
percent = Decimal.Divide(value, total) * 100;
if(places > 0)
{
strplaces = "." + strplaces;
}
}
retval = percent.ToString("#" + strplaces);
return retval;
}