Home
<!DOCTYPE html> <html> <body> <h1>Demo: Floating-point in JavaScript</h1> <p id="p1">123456789012345.9 = </p> <p id="p2">1234567890123456.9 = </p> <p id="p3">1234567890123456.79 = </p> <script> //17 decimal places var f1 = 123456789012345.9; //accurate //18 decimal places var f2 = 1234567890123456.9; //will be 1234567890123457 //19 decimal places var f3 = 1234567890123456.79; //will be 1234567890123456.8 document.getElementById("p1").textContent += f1; document.getElementById("p2").textContent += f2; document.getElementById("p3").textContent += f3; </script> </body> </html>
Result: