From: Dr J R Stockton on
In comp.lang.javascript message <a44d7175-3081-4ecf-b42a-1196395154ba(a)q1
6g2000prf.googlegroups.com>, Thu, 29 Jul 2010 16:53:11, dhtml
<dhtmlkitchen(a)gmail.com> posted:

>On Jul 29, 1:03�pm, Dr J R Stockton <reply1...(a)merlyn.demon.co.uk>
>wrote:
>> In comp.lang.javascript message <4c4f64f9$0$279$14726...(a)news.sunsite
>>.dk>, Tue, 27 Jul 2010 23:00:03, FAQ server
>><javascr...(a)dotinternet.be>
>>
>> posted:
>>
>> >FAQ Topic - How do I format a Number as a String with
>> >exactly 2 decimal places?
>> >ECMA-262 3rd Edition introduced `Number.prototype.toFixed`.
>> >There are bugs in JScript's implementation with certain numbers,
>> >for example `0.07`.
>>
>> No, there is no bug with toFixed formatting 0.07 as per Subject.
>>
>> � � � � 0.07.toFixed(2) � � � � -> � � �'0.07'
>>
>> You have been told, more than once IIRC, and have agreed at least once,
>> that the example should be 0.007 or similar.
>>
>> NOW is the time to make the correction.
>>
>
>I believe that I had changed it from 0.007 to 0.07 per your request,

I think not. It was 0.07 in versions 8.1 (Cornford) and 9.91 (Webb).

>though I don't have the thread on hand. I see that introduced a
>mistake and so I'll change it back.

Good.

--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
From: Dr J R Stockton on
In comp.lang.javascript message <9b483dcc-3075-40f4-9e5a-eaa9404ad31d(a)o7
g2000prg.googlegroups.com>, Thu, 29 Jul 2010 16:45:57, dhtml
<dhtmlkitchen(a)gmail.com> posted:

>
>Function `numberToFixed` is intended as a fallback for buggy JScript.
>The function itself is still somewhat undesirable because it relies on
>IEEE754 rules and so sometimes you'll see a result that is odd.

It is specified in ECMA. If a browser maker wishes to implement it
using a FPU, he must check that the FPU is ECMA-compliant, whatever IEEE
754 says.

ISTM likely that 754 supports both compliant rounding and some other
form, such as Bankers'; and possible that MS chose wrongly.
<URL:http://www.merlyn.demon.co.uk/js-rndg1.htm#toF> demonstrates that
MS are a load of Bankers.

>javascript:alert(1.255.toFixed(2));
>
>May result 1.25 or 1.26, depending on the implementation.
>

AFAICS, ECMA 262 5 15.7.4.5 8 requires rounding up, if the (IEEE Double)
Number is equally near to two adjacent strings. But Web page
<URL:http://www.merlyn.demon.co.uk/js-exact.htm#DW4> shows that the
literal 1.255 will be stored as 3ff4147ae147ae14, the value of which is
+1.25499999999999989341858963598497211933135986328125 - therefore, the
correct result is 1.25.

Firefox 3.0.19, Opera 10.10, Safari 5.0, Chrome 5.0 give 1.25;
MSIE 8 gives 1.26;
StrU("1.255", 0, 2), which the FAQ method resembles, gives 1.25.

YAMB (Yet Another Microsoft Bug). Now in <js-datex.htm>.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)