728x90

C# 에서 %를 구하는 함수다.

구글링하면 온갖 함수들이 나오는데 시간낭비다.

제공되는 Math.Round 함수를 이용하면 한줄이면 된다.


private double GetPercentage(double value, double total, int decimalplaces)
{
    return System.Math.Round(value * 100 / total, decimalplaces) ;
}


사용예제

string.Format("입력 : {0} (전체의 {1}%)", cnt, GetPercentage(cnt,DBtotalcnt(),2));

블로그 이미지

Link2Me

,