function erpround(val) {
	var negative = false;
	
	if (val < 0) {
		val = val * -1;
		negative = true;
	} else {
		negative = false;
	}
	
	// Preround to get rid of floating point errors {
		bigval = parseInt(val * 100000);
		smallval = parseInt(val * 10000) * 10;
		diffvals = bigval - smallval;
		
		if (diffvals >= 5) {
			val = ((bigval+'').slice(0, -1) * 1) + 1;
		} else {
			val = ((bigval+'').slice(0, -1) * 1);
		}
	//}
	
	bigval = (val+'').slice(0, -3) * 1;
	smallval = (val+'').slice(0, -4) * 10;
	diffvals = bigval - smallval;
	
	if (diffvals >= 5) {
		val = ((bigval+'').slice(0, -1) * 1) + 1;
	} else {
		val = ((bigval+'').slice(0, -1) * 1);
	}
	
	if (negative) {
		val = val * -1;
	}
	
	val *= 1;
	
	return val;
}

Math.round = erpround;

function number_format(value, decimals){
	if (decimals === false){decimals = 2;}
	if (decimals == undefined) {decimals = 2;}
	multiplier = Math.pow(10, decimals);
	
	if (value < 0) {
		value = value * -1;
		negative = true;
	} else {
		negative = false;
	}
	
	nval = Math.round(value*multiplier)+'';
	len = nval.length;
	
	if (len == 1) {
		addzero = '0';
	} else {
		addzero = '';
	}
	
	deci = addzero + nval.substr(len-decimals,decimals);
	
	multiplier += '';
	deci = deci*1 ? deci : multiplier.substr(1);

	num = nval.substr(0,len-decimals);
	num = num ? num : '0';

	temp = (num.split('')).reverse();
	cnt = 3;
	while (temp[cnt]){
		if (temp[cnt] != '-'){
			temp[cnt] = temp[cnt]+',';
		}
		cnt = cnt+3;
	}
	num = (temp.reverse()).join('');
	
	nval = deci ? num+'.'+deci : num;
	
	if (negative) {
		nval = '-'+nval;
	}

	return nval;
}
