Precision

Integers (numbers without a period or exponent notation) are considered accurate up to 15 digits.
   define variable to = 999999999999999;  <== 15 digits will return 999999999999999
   define variable to = 9999999999999999;  <== 16 digits will return 10000000000000000

The maximum number of decimals is 17, but floating point arithmetic is not always 100% accurate:
   define variable to = 0.2 + 0.1;  <== result will be 0.30000000000000004

To solve the problem above, it helps to multiply and divide:
   define variable to = (0.2 * 10 + 0.1 * 10) / 10;  <== result will be 0.3

HTML file: Displayed by browser:
<body>
<h4>Integers are considered accurate up to 15 digits:</h4>
<p id="demo"></p>
<hr />
<h4>Floating point arithmetic is not always 100% accurate:</h4>
<p id="demo1"></p>
<hr />
<h4>But it helps to multiply and divide:</h4>
<p id="demo2"></p>
<script>
    var w = 999999999999999
    var x = 9999999999999999
    var y = 0.2 + 0.1;
    var z = (0.2*10 + 0.1*10) / 10;
    document.getElementById("demo").innerHTML = w + "<br />" + x;
       // Results are in the first section
    document.getElementById("demo1").innerHTML = "0.2 + 0.1 = " + y;
       // Results are in the second section
    document.getElementById("demo2").innerHTML = "0.2 + 0.1 = " + z;
       // Results are in the last section
</script>
</body>

Integers are considered accurate up to 15 digits:


Floating point arithmetic is not always 100% accurate:


But it helps to multiply and divide:


BackTable of ContentsNext