0%

Javascript Math函数用法

Math函数主要用于数字的处理

var a=6.448;
var b=9;
document.write("进一取整:"+Math.ceil(a)+"");
document.write("去尾取整:"+Math.floor(a)+"");
document.write("四舍五入取整:"+Math.round(a)+"");
document.write("返回最小值:"+Math.min(a,b)+"");
document.write("返回最大值:"+Math.max(a,b)+"");
document.write("求幂,a的b次方:"+Math.pow(a,b)+"");
document.write("生成0-1之间的随机数:"+Math.random()+"");
document.write("开平方:"+Math.sqrt(b)+"");