br /span class=postbody다들 학교에서 배운기억이 있는 비율계산하는 방법에 대해서 적어봅니다.
br /
br /
프로그래밍을 하다가 보면 특정 scale 범위의 값을 지정한 scale 범위를 갖는 값으로 변환하여 사용해야 하는 경우가 종종 발생합니다.
br /
br /
통상적으로 비율은 다음과 같이 표시합니다.
br /
br /
/spantable align=center border=0 cellpadding=3 cellspacing=1 width=90%tbodytr tdspan class=genmedb인용:/b/span/td /tr tr td class=quotex1 : x2 = y1 : y2/td /tr/tbody/tablespan class=postbody
br /
br /
그리고 이것은 다음과 동일한 등가식입니다. (사실상 이 등가식만 알면 모든것은 끝났습니다. 이것만으로 어떠한 비율이라도 구할수 있게 됩니다.)
br /
br /
/spantable align=center border=0 cellpadding=3 cellspacing=1 width=90%tbodytr tdspan class=genmedb인용:/b/span/td /tr tr td class=quotex1 * y2 = x2 * y1/td /tr/tbody/tablespan class=postbody
br /
br /
이를 활용하여 백분율은 다음과 같이 정의되어 계산될수 있습니다.
br /
br /
/spantable align=center border=0 cellpadding=3 cellspacing=1 width=90%tbodytr tdspan class=genmedb인용:/b/span/td /tr tr td class=quotex : 100 = value : max
br /
x * value = 100 * max
br /
x = ( 100 * value ) / max/td /tr/tbody/tablespan class=postbody
br /
br /
여기서 예를 들면 총 500개의 사과가 있다고 했을때 이중에 20% 는 몇개의 사과를 말할까요?
br /
br /
/spantable align=center border=0 cellpadding=3 cellspacing=1 width=90%tbodytr tdspan class=genmedb인용:/b/span/td /tr tr td class=quote20 : 100 = x : 500
br /
20 * 500 = 100 * x
br /
x = ( 20 * 500 ) / 100 = 10000 / 100 = 100/td /tr/tbody/tablespan class=postbody
br /
br /
즉, 500개 중에서 20%는 100개가 됩니다.
br /
br /
br /
br /
프로그래밍에서의 백분율 표시는 이렇게도 구현할수 있을겁니다.
br /
br /
/spantable align=center border=0 cellpadding=3 cellspacing=1 width=90%tbodytr tdspan class=genmedb코드:/b/span/td /tr tr td class=codevoid print_percent(long s_value, long s_max)
br /
{
br /
long long s_man;
br /
br /
s_man = (((long long)s_value) * 10000ull) / s_max;
br /
br /
(void)fprintf(stdout, %llu.%02llu%%\n, s_man / 100ull, s_man % 100ull);
br /
}/td /tr/tbody/tablespan class=postbody
br /
br /
위의 예제소스는 소수점이하 2자리까지만 표시하고 소수점 계산을 회피하고 정수계산만으로 소수점이하 2자리를 표시하기 위해서 백분율을 만분율로 계산하여 정부부분과 소수점부분을 100 이라는 배율값으로 나누어지게 구현한 것입니다.
br /
br /
이 밖에도 비율공식은 너무 광범위하게 사용되므로 꼭 머리속에 새겨넣어야 하는 공식중에 한가지라고 주장합니다./spanbr /
받은 트랙백이 없고,
댓글 span class="cnt"하나/span가 달렸습니다.

글
댓글을 달아 주세요
댓글 RSS 주소 : http://blog.minzkn.com/rss/comment/209댓글 ATOM 주소 : http://blog.minzkn.com/atom/comment/209
참 부끄러운 일인데요.
워낙 기초가 안되기도 하고- 선천적으로 산수를 못하는기도 하고;;-
해서 늘 백분율을 구해야 할때 매번 똑같은걸 손으로 써보고서야
하곤 했습니다;
위 포스팅을 보고 기초적 공식을 숙지해야겠단 생각이 드네요.
간단 명료 하면서도 머리에 쏙 들어 옵니다 ..^^
좋은글 잘 읽었습니다 ( _ _)