日期:2014-05-16  浏览次数:20339 次

javascript 四舍五入保存n位小数

?

/**
		  * 四舍五入,保留位数为
		  * @param numberRound 
		  */
		function roundFun(numberRound,roundDigit){   //四舍五入,保留位数为roundDigit    
			if (numberRound>=0){  
				var tempNumber = parseInt((numberRound * Math.pow(10,roundDigit)+0.5))/Math.pow(10,roundDigit);  
				return tempNumber;  
			}else{  
				numberRound1 = -numberRound  
				var tempNumber = parseInt((numberRound1 * Math.pow(10,roundDigit)+0.5))/Math.pow(10,roundDigit);  
				return -tempNumber;  
			}  
		}  
?