浮点算术不总是 100% 精确

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 数字</h1>
  6.  
  7. <p>浮点的算数并不总是 100% 精准:</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var x = 0.2 + 0.1;
  13. document.getElementById("demo").innerHTML = "0.2 + 0.1 = " + x;
  14. </script>
  15.  
  16. </body>
  17. </html>