Bug 5308 - Number.toFixed doesn't include leading zero
Summary: Number.toFixed doesn't include leading zero
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Darin Adler
URL: javascript:alert((0.5).toFixed(1))
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-09 11:33 PDT by Bob Ippolito
Modified: 2006-01-11 08:59 PST (History)
0 users

See Also:


Attachments
Patch and test case for 5308 (2.26 KB, patch)
2006-01-03 20:59 PST, Ricci Adams
eric: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Ippolito 2005-10-09 11:33:59 PDT
(0.5).toFixed(1) is ".5".  (0.5).toString() is "0.5" and other browsers return "0.5" for both.
Comment 1 Ricci Adams 2006-01-03 02:43:41 PST
ECMA-262 Section 15.7.4.5 states that:

13. Let k be the number of characters in m.
14. If k > f, go to step 18.

We are implementing this by creating an if block containing steps 15-17.  Unfortuately, the statement 
we are using is:

      if (m.size() < f) {
            // Execute steps 15-17
      }
      // Step 18...

Hence, we are assuming that (k > f) is the same as !(k < f).  This is logically not the case.  I believe that 
the correct line is:

      if (m.size() <= f) {

Unfortuately, I'm too tired to create/test a patch now.  I will try to attach one later this week.
Comment 2 Ricci Adams 2006-01-03 20:59:26 PST
Created attachment 5468 [details]
Patch and test case for 5308

Patch attached.  This is basically changing the < to a <=.  I also changed
m.size() to k in order to make the code read more like the algorithm.
Comment 3 Eric Seidel (no email) 2006-01-03 22:26:20 PST
Comment on attachment 5468 [details]
Patch and test case for 5308

Looks fine.  An even better test case would print "success" or "failure" to be
more clear.