수학관련 함수



/**
소수검사
*/
function chkPrime(n) 
{
	if(n == 1) {return false;};
	for(i=2; i<n; i++) {	if(n%i == 0){return false}};
	return true;
};

/**
퍼센트
*/
function getPercent(v,t){if(v){return (v/t)*100;}else{return 0;}};

/**
전체 값에서 퍼센트에 해당하는 값을 뺀 값
*/
function getDepercentRemain(per,total){	return t-((p/100)*t);};

/**
퍼센트에 해당하는 값
*/
function getDepercent(p,t){	return (p/100)*t;};

/**
전체 값
*/
function getTotalPercent(p,v){	return (v/p)*100;};

/**
* 랜덤 / 참고 : http://blog.naver.com/hika00?Redirect=Log&logNo=150025341786
*/
function GetRandom(b,t)
{
	arr = new Array();
	k = Math.floor(Math.random()*10)%3;
	arr[0] =  b+Math.random()*(t+1-b);
	arr[1] =  b+Math.random()*(t+1-b);
	arr[2] =  b+Math.random()*(t+1-b);
	return arr[k];
};

/**
* http://kr.php.net/manual/kr/function.log.php
*/
function byteConvert(b)
{
	s = new Array('B', 'Kb', 'MB', 'GB', 'TB', 'PB');
	e = Math.floor(Math.log(b)/Math.log(1024));
	r = b/Math.pow(1024, Math.floor(e));
	return r+s[e];
};

/**
* 소수점 자리수(l)까지 절삭
*/
function cutFloor(f,l)
{
	if(typeof(l) == "undefined"){l=3};
	l = Math.pow(10,l);
	f = Math.floor(f*l)/l;
	return f;
};
/**
* 반올림후 자리수(l)까지 절삭
*/
function cutRound(f,l)
{
	if(typeof(l) == "undefined"){l=3}
	l = Math.pow(10,l);
	f = Math.round(f*l)/l;
	return f;
};



'Javascript' 카테고리의 다른 글

DOM 프로퍼티  (0) 2009.11.04
에러처리  (0) 2009.10.16
fieldset 그룹박스  (0) 2008.12.26
전화번호,휴대전화 검사 / 자동"-"넣기  (0) 2008.12.15
Trim()  (0) 2008.12.13