得到两数相除的百分数

原理:
Math.ceil()   //向上取整
Math.floor()  //向下取整
Math.round()  //四舍五入取整


第一种:得到的是整数
function percentNum(num, num2) { 
	return Math.ceil(num / num2 * 100) + '%';
}

alert(percentNum(2,3));



第二种:得到的是整十数
function percentNum(num, num2) { 
	return (Math.floor(num / num2 * 10))*10 +'%';
}

alert(percentNum(2,3));



第三种:得到的是保留两位小数的数
function percentNum(num, num2) { 
	return Math.round(num / num2 * 10000 ) / 100 + '%';
}

alert(percentNum(2,3));


猜你喜欢

转载自hiuman.iteye.com/blog/2346293
今日推荐