function roundNumber(n,dp) {

	var s = new String(n);
	var length = s.length;
	var wholeNumber = new String();
	var decimals = new String();
	var maxDecimalNumber = Math.pow(10,dp)-1; // this is the maximum value of the decimal portion - eg if dp is 2 then this will be 99
	
	var pointPos = -1;
	for (i=0;i<length;i++) {
		if (s.charAt(i) == ".") {
			pointPos = i;
			break;
		} 
		wholeNumber += s.charAt(i);		
	}
	wholeNumberInt = parseInt(wholeNumber);
	
	if (pointPos != -1) {
		for(i=pointPos+1;i<pointPos+dp+1;i++) {
			decimals += s.charAt(i);
		}
	}
	decimalsInt = parseInt(decimals);
	
	var startPos = pointPos+dp+1;
	var fullNumberInt = 0; // this is the whole decimal number ie. if n = 12.3567 fullNumberInt will be 3567
	var midNumberInt = 0; // if fullNumberInt is bigger than this then round up ie. if n=12.3567 and dp=2 then this will be 3550
	
	if (startPos < length) {
		midNumber = decimals+"5";
		for (i=startPos+1;i<length;i++) {
			midNumber += "0";
		}
		midNumberInt = parseInt(midNumber);
		fullNumber = s.substr(pointPos+1,length-pointPos-1);
		fullNumberInt = parseInt(fullNumber);
		
		// ie if n = 9.9969 and dp = 2 : round up if 9969 >= 9950
		if (fullNumberInt >= midNumberInt) {
			decimalsInt++;
			if (decimalsInt > maxDecimalNumber) {
				wholeNumberInt++;
				decimalsInt=0;
			}
		}
	}
	
	// pad with zeros
	decimals = new String(decimalsInt);
	if (decimals.length < dp) {
		extraZeros = dp - decimals.length; 
		for(i=0;i<extraZeros;i++) {
			decimals += "0";
		}
	}
	numberStr = wholeNumberInt;
	if (dp > 0) {
		numberStr += "." +decimals;
	}
	
//	alert(n+":"+numberStr+":max-"+maxDecimalNumber+":dec-"+decimalsInt+":full-"+fullNumberInt+":mid-"+midNumberInt);

	return(numberStr);
}
