<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alan Jones on Medium]]></title>
        <description><![CDATA[Stories by Alan Jones on Medium]]></description>
        <link>https://medium.com/@alanrandojones?source=rss-dc16df6030f7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XcgZkB9vIUHnSbCYKpcNXA.jpeg</url>
            <title>Stories by Alan Jones on Medium</title>
            <link>https://medium.com/@alanrandojones?source=rss-dc16df6030f7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:09:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alanrandojones/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Watch Out For Floating-Point Arithmetic in Web Browsers!]]></title>
            <link>https://medium.com/@alanrandojones/watch-out-for-floating-point-arithmetic-in-web-browsers-d89d841085ce?source=rss-dc16df6030f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d89d841085ce</guid>
            <category><![CDATA[arithmetic]]></category>
            <category><![CDATA[floating-points]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[bad-math]]></category>
            <dc:creator><![CDATA[Alan Jones]]></dc:creator>
            <pubDate>Thu, 26 Apr 2018 23:35:26 GMT</pubDate>
            <atom:updated>2018-04-26T23:35:26.865Z</atom:updated>
            <content:encoded><![CDATA[<p>When working with JavaScript, you’re going to end up asking your browsers to do math. With simple integers, this is usually fine, but you may encounter problems if you’re dealing with very large or very small numbers, especially if you’re working with decimal places. For example, type this equation into your console browser and see what comes out:</p><blockquote>0.1 + 0.2</blockquote><p>You expect to see 0.3. The question is simple arithmetic, just moved down one decimal point. But you don’t get 0.3. You get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/1*QIPB2Wjo_UBlObaq9Q7YTA.png" /><figcaption>Whaaaaa?</figcaption></figure><p>The reason for this is that browsers use <a href="https://en.wikipedia.org/wiki/Floating-point_arithmetic">floating-point arithmetic</a>. It’s all very complicated, but the general idea is that computers (understandably) can’t store information for an <strong>infinite</strong> amount of numbers, and so they take shortcuts, which can produce inaccuracies.</p><p>When you’re dealing with decimal points, this can lead to unexpected rounding errors, even when using methods like <em>toFixed()</em>. There are workarounds to problems like this (see below), but the short answer is that browsers aren’t the most reliable calculators, so don’t rely on JavaScript to do math on numbers with lots of decimal points, <em>especially</em> if your boss or client requires accurate numbers for whatever reason.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*34QujCgVBI-pji5pAhjQnQ.png" /><figcaption>Multiply the parameters by 10 *before* adding them together, then divide the answer by 10.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*mG5h1uHuaXEPMNX51blrDg.png" /><figcaption>et voilà!</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d89d841085ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>