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));
728x90
'C# > 문법 및 기능' 카테고리의 다른 글
C# Trackbar 기능 및 타이머 연결 (0) | 2015.12.08 |
---|---|
C# 문자열 숫자형식 포맷팅 String.Format (0) | 2015.12.06 |
C# 파일 다중선택 열기(OpenFileDialog) (3) | 2015.12.01 |
C# 파일 복사(File Copy) - 중복체크 (0) | 2015.11.22 |
C# HttpWebRequest 를 이용한 POST 전송하기 (0) | 2015.11.13 |