源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>浮点运算并不总是100%准确.</p> <p>但是它可以辅助乘法和除法.</p> <button onclick="myFunction()">试试</button> <p id="demo"></p> <script> function myFunction() { var x = (0.2*10 + 0.1*10) / 10; document.getElementById("demo").innerHTML = "0.2 + 0.1 = " + x; } </script> </body> </html>
运行结果