本文实例讲述了JavaScript常用数学函数用法。分享给大家供大家参考,具体如下:
一、代码
<script language="javascript"><!--document.write("欧拉常数e的值为(e属性):"+Math.E+"<br>");document.write("2的自然对数为(LN2属性):"+Math.LN2+"<br>");//2的几次方等于edocument.write("10的自然对数为(LN10属性):"+Math.LN10+"<br>");//10的几次方等于edocument.write("7的自然对数(log()方法):"+Math.log(7)+"<br>");//7的几次方等于edocument.write("0的自然对数(log()方法):"+Math.log(0)+"<br>");document.write("-1的自然对数(log()方法):"+Math.log(-1)+"<br>");document.write("2的自然对数(log()方法):"+Math.log(2)+"<br>");//2的几次方等于edocument.write("以2为基数的e的对数的值:"+Math.LOG2E+"<br>");//E的几次方等于2document.write("以10为基数的e的对数的值:"+Math.LOG10E+"<br>");//E的几次方等于10document.write(Math.SQRT1_2);//0.5的平方根document.write(Math.SQRT2);//2的平方根document.write("2的平方根:"+Math.sqrt(2)+"<br>");document.write("4的平方根:"+Math.sqrt(4)+"<br>");document.write("5的平方根:"+Math.sqrt(5)+"<br>");document.write("10的平方根:"+Math.sqrt(10));document.write("-2的绝对值:"+Math.abs(-2)+"<br>");document.write("0的绝对值:"+Math.abs(0)+"<br>");document.write("2的绝对值:"+Math.abs(2)+"<br>");document.write("2.7的绝对值:"+Math.abs(2.7)+"<br>");document.write("-2.7的绝对值:"+Math.abs(-2.7));document.write("1的正弦值:"+Math.sin(1)+"<br>");document.write("0的正弦值:"+Math.sin(0)+"<br>");document.write("-1的正弦值:"+Math.sin(-1)+"<br>");document.write("1的反正弦值的正弦值:"+Math.sin(Math.asin(1))+"<br>");document.write("1的余弦值:"+Math.cos(1)+"<br>");document.write("0的余弦值:"+Math.cos(0)+"<br>");document.write("-1的余弦值:"+Math.cos(-1)+"<br>");document.write("1的反余弦值的余弦值:"+Math.cos(Math.acos(1))+"<br>");document.write("1的正切值:"+Math.tan(1)+"<br>");document.write("0的正切值:"+Math.tan(0)+"<br>");document.write("-1的正切值:"+Math.tan(-1)+"<br>");document.write("1的反正切值的正切值:"+Math.tan(Math.atan(1))+"<br>");document.write("3和5中的最大数:"+Math.max(3,5)+"<br>");document.write("3和5中的最小数:"+Math.min(3,5)+"<br>");document.write("-3和5中的最大数:"+Math.max(-3,5)+"<br>");document.write("-3和5中的最小数:"+Math.min(-3,5)+"<br>");document.write("3.5和3.4中的最大数:"+Math.max(3.5,3.4)+"<br>");document.write("3.5和3.4中的最小数:"+Math.min(3.5,3.4));document.write("对7.5进行四舍五入:"+Math.round(7.5)+"<br>");document.write("对7.3进行四舍五入:"+Math.round(7.3)+"<br>");document.write("对-7.8进行四舍五入:"+Math.round(-7.8)+"<br>");document.write("对-7.3进行四舍五入:"+Math.round(-7.3));document.write("对7.7进行上舍入:"+Math.ceil(7.7)+"<br>");document.write("对7.3进行上舍入:"+Math.ceil(7.3)+"<br>");document.write("对-7.8进行上舍入:"+Math.ceil(-7.8)+"<br>");document.write("对-7.3进行上舍入:"+Math.ceil(-7.3));document.write("对7.7进行下舍入:"+Math.floor(7.7)+"<br>");document.write("对7.3进行下舍入:"+Math.floor(7.3)+"<br>");document.write("对-7.8进行下舍入:"+Math.floor(-7.8)+"<br>");document.write("对-7.3进行下舍入:"+Math.floor(-7.3));//--></script>
新闻热点
疑难解答
图片精选