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