Skip to content

Commit 02676eb

Browse files
committed
Updates data-types/51-numbers.md
Auto commit by GitBook Editor
1 parent f9ec7e6 commit 02676eb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

data-types/51-numbers.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ The `Number.isSafeInteger()` function can be used to determine if a number is an
3030
<div class="tip-box">
3131
<h2>Unexpected Math</h2>
3232
<p>JavaScript does not have a way of restricting "floating point" or "decimal" numbers to a specific number of places. We can use methods like <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed">Number.toFixed()</a></code> to round off at a specific decimal point, but we can always expect to see weird things like this:</p>
33-
<p><code>
33+
<pre>
3434
let total = 0.10 + 0.20; // expected result is 0.3 (or maybe 0.30) <br>
3535
console.log(`Actual value of total is: ${total}`); // prints 0.30000000000000004 to the console.
36-
</code></p>
36+
</pre>
3737
<p>This all stems from the fact that numbers with decimal points in JavaScript are all treated as "floating point" numbers, which is not the precise "decimal" numbers we are used to dealing with in our finances or other aspects of our daily lives. We won't dive into what makes "floating point" numbers work, but we can recognize and anticipate that we might encounter trouble working with decimal numbers in JavaScript when dealing with decimals. If we are working on certain types of applications, we may need to explore some different methods for working around the unexpected results of floating point math.</p>
3838
</div>
3939

0 commit comments

Comments
 (0)