本文實例講述了JavaScript里四舍五入函數round用法。分享給大家供大家參考。具體如下:
JavaScript的Math對象包含了一個round方法用于對數字進行四舍五入操作,下面的代碼詳細演示了其用法
<!DOCTYPE html><html><body><p id="demo">Click the button to round the number 2.5 to its nearest integer.</p><button onclick="myFunction()">Try it</button><script>function myFunction(){document.getElementById("demo").innerHTML=Math.round(2.5);}</script></body></html>希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答