Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Created August 3, 2010 01:02
Show Gist options
  • Save huacnlee/505623 to your computer and use it in GitHub Desktop.
Save huacnlee/505623 to your computer and use it in GitHub Desktop.
/// <summary>
/// 根据好与不好的支持率算出好的占多少%
/// </summary>
/// <param name="bad">不好</param>
/// <param name="good">好</param>
/// <returns></returns>
public static string TotalScore(int bad, int good)
{
if (good == 0 && bad == 0)
{
return "50%";
}
if (good == 0)
{
return "0%";
}
if (bad == 0)
{
return "100%";
}
int count = good + bad;
double per = count / 100.00;
double goodNum = good / per;
return Math.Round(goodNum,2) + "%";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment