本文實例講述了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>
新聞熱點
疑難解答
圖片精選