From: dhtml on
On Jul 28, 9:16 am, kangax <kan...(a)gmail.com> wrote:
> On 7/27/10 7:24 PM, Ry Nohryb wrote:
>
>
>
>
>
>
>
>
>
> > On Jul 28, 1:00 am, "FAQ server"<javascr...(a)dotinternet.be>  wrote:
> >> -----------------------------------------------------------------------
> >> FAQ Topic - How do I format a Number as a String with
> >> exactly 2 decimal places?
> >> -----------------------------------------------------------------------
> >> (...)
>
> > This is the problem. JavaScript coding style bent to suit IE's bugs.
> > NO, please, no. The proper way to do this is :
>
> > (number).toFixed(decimalPlaces) -->  string
>
> > For example:
>
> > Math.PI.toFixed(3)
> > "3.142"
>
> > or
>
> > (6).toFixed(2)
> > -->  "6.00"
>
> > That's what ought to come FIRST in this FAQ entry, and it should be
> > the recommended way of doing it.
>
> > Then, -*only*after*having*said*that*in*the*first*place*-, you can also
> > say that IEs have got (yet another) bug that affects
> > Number.prototype.toFixed(), sooo, in IEs you could do instead:
>
> > (blah, blah, blah)
>
> Does `numberToFixed` from the FAQ entry solve anything that fully
> compliant `Number.prototype.toFixed` doesn't? From what I can see, they
> should be identical.
>

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.

javascript:alert(1.255.toFixed(2));

May result 1.25 or 1.26, depending on the implementation.

> If they are, then why not employ a feature test and skip workaround once
> implementation is determined to be compliant? At least for performance
> reasons.
>

Sure, use `Number.prototype.toFixed` where the known errors aren't
apparent. I remember struggling with trying to nail down identifying
what is buggy and what is acceptable and I ended up coming to writing
a function that will work consistently across browsers without having
to identify various differences.

Posting now via GG, which is not quite as "Comcastic" as my ISP, which
is almost on the same level as Dell computer manufacturer, which
claims that Win 7 cannot run on the computer I own (only the wireless
network drivers fail).

"Don't own a computer on this list? Click here to shop for a new
Dell!" http://dell.to/df9KMn

Most of the pages for Dell work in Firefox, but many are IE 5.5+
only.

http://support.dell.com/support/topics/global.aspx/support/my_systems_info/en/FindTagSysProfLicense?c=us&cs=19&l=en&parent=formSupportRequestEnterTag&s=dhs&~mode=popup

--
Garrett
From: dhtml on
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,
though I don't have the thread on hand. I see that introduced a
mistake and so I'll change it back.
--
Garrett