Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: IE and IEE 754 Date: Thu, 28 Aug 2014 00:47:16 +0200 Organization: solani.org Lines: 40 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1409179629 26262 eJwFwYkBwCAIA8CVxBCecVo0+4/gHREWkx4Mp6hG6XRb8hBuN4G4H7nOXmpOzb/dhNoGSfYAB34QgA== (27 Aug 2014 22:47:09 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Wed, 27 Aug 2014 22:47:09 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 X-User-ID: eJwFwYEBwCAIA7CXBNpOzwEm/59gwpCpP4gCh1OcbTfYU+mOjdMjlMca2vkzCNpNW64FVTwc0RCP In-Reply-To: Cancel-Lock: sha1:3kNf/LOfIm1j8Co50DcTL5BG0to= X-NNTP-Posting-Host: eJwNycEBwCAIA8CVQAjQcUTJ/iPY+x4sNE56IBwEZwvIGdT6bt2zzSkT1pw1DFT6f8mS1drUBzmuEdQ= Xref: csiph.com comp.lang.javascript:25747 Evertjan. wrote: > "Christoph M. Becker" wrote on 27 aug 2014 in > comp.lang.javascript: > > I wes not talking about the integer type, > I was not talking about Javascript [ECMA if you like], > but about integers. Well, then you're off topic. > Compare this to: > > document.write(23.45-23.4); // 0.05000000000000071 > > You are quite in your right > not to call the first method "better", > but in monetary calculus, I would disagree. Well, then try to calculate the German VAT with "integers": 2345 * 1.19 -> 2790.5499999999997 Ah, we have to round the result: (2345 * 1.19).toFixed(0) -> 2791 Or: (23.45 * 1.19).toFixed(2) -> 27.91 Hm, same result (but see for very old browsers). Anyway, you can't do arbitrary monetary calculations reliably with IEEE 754 doubles. However, that is the only number type that is guaranteed to be supported by conforming ECMAScript implementations. -- Christoph M. Becker