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: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: IE and IEE 754 Date: Thu, 28 Aug 2014 12:21:21 +0200 Organization: PointedEars Software (PES) Lines: 45 Message-ID: <5003685.scHRlTtjAS@PointedEars.de> References: <87fvgh1qu9.fsf@bsb.me.uk> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1409221284 11522 eJwFwYEBwCAIA7CXEGnRczbW/n/CEmwuThfBguG0ltFVVwpnB+Yc6Nwm0zunI1Tx+sHnEX4TUBEU (28 Aug 2014 10:21:24 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 28 Aug 2014 10:21:24 +0000 (UTC) User-Agent: KNode/4.14 X-User-ID: eJwNy8EBwCAIA8CVUiCo4wQq+4/Q3v/o+WSvSGZwOC7YmSp7b/UtscXCNSpa7arNV0tQYf8Dq4ETPsOctM0Pj4QWXg== Cancel-Lock: sha1:iU4hfaVxN8on6P0rnugF8DvDuhM= X-NNTP-Posting-Host: eJwNytEVACAEBdCVEI/GCdl/hPq959oCo1xhUBubgp4OzSrkxOYkiW5iwX/x6fS+y0OdMuTWAyYaETs= Xref: csiph.com comp.lang.javascript:25755 Evertjan. wrote: > "Christoph M. Becker" wrote: >> However, it seems to me that multiplying 123.45 (0x405edccccccccccd) >> with 100 doesn't solve the issue, i.e. the result is not necessarily >> equal to 12345 (0x40c81c8000000000). > > No, as I said, it is the string that is -ted, > and that should be converted by string [regexed if you like] methods. > > a = 123.45; // expecting 2 decimals, extra code needed if otherwise > b = +a.split('.').join(''); There is no Number.prototype.split() by default. You mean String.prototype.split(): var b = a.toString().split('.').join(''); or (in this case equivalent) var b = String(a).split('.').join(''); but this does not solve the problem because it is based on the very same string representation of the Number value. It can only be solved if you have string input in the first place, like from an HTML form: /* BTW see jsx.array.destructure() for an emulation of JavaScript 1.7’s Array destructuring */ var parts = input.value.split('.'); var int_part = parts[0]; var frac_part = parts[1]; var value = int_part * 100 + (+frac_part); /* calculate with value */ var result = … / 100; -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.