Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!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: Fri, 29 Aug 2014 01:16:40 +0200 Organization: solani.org Lines: 42 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1409267792 22890 eJwNyMERACEIA8CWRAORchi49F+Ct8/1ExZNhAdcLs3icM/ND/y7y00Uq9gnK5lAXyyvMW3aAx+4EOs= (28 Aug 2014 23:16:32 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 28 Aug 2014 23:16:32 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 X-User-ID: eJwFwYkBABAMA8CV+kjKOKjsP4I7JJ23BsEBQdppfGsuIuu9ths36qzMkKJJbZ++YTDv1vkauBEw In-Reply-To: Cancel-Lock: sha1:8ErrOysUyo4eV3AbPFuOs7BR1P0= X-NNTP-Posting-Host: eJwNxskBwDAIA7CZuEw8DiSw/witXgqD4KYj4LGxfEI/jmL3rIFaf3yzYDHZorgYqjC7evUDIlMRcQ== Xref: csiph.com comp.lang.javascript:25768 Evertjan. wrote: > "Christoph M. Becker" wrote on 28 aug 2014 in > comp.lang.javascript: > >>>> Well, then try to calculate the German VAT with "integers": >>>> >>>> 2345 * 1.19 -> 2790.5499999999997 >>> ^^^^ >>> This is not an integer. >> >> No, of course not. I just wanted to show that storing dollars as cents >> doesn't solve all problems regarding monetary calculations. Of course, >> one could use the following instead: >> >> 2345 * 119 / 100 > > No that would not help. > It seems your mathematic skills leave much to be desired. Of course, that would not help. I did not suggest that as a solution, but rather to reply to Gene's complaint that "this is not an integer". > The cents approach solves the problems > of binary conversion inaccuracies, > but you still have to be a good programmer. The "cents approach" is usually not exact enough. Intermediate calculations may well require more precision, and sometimes even "final" results, for instance some stock quotations. > Adding and substracting of cents will be exact. > Multiplying with an integer too. You should consider "overflow". AISB: | IMHO one is better off to use a bigint library when there is really | the need for exact integer calculations. -- Christoph M. Becker