使用 round() 对数字进行舍入

  1. <html>
  2. <body>
  3.  
  4. <script type="text/javascript">
  5.  
  6. document.write(Math.round(0.60) + "<br />")
  7. document.write(Math.round(0.50) + "<br />")
  8. document.write(Math.round(0.49) + "<br />")
  9. document.write(Math.round(-4.40) + "<br />")
  10. document.write(Math.round(-4.60))
  11.  
  12. </script>
  13.  
  14. </body>
  15. </html>