Bug 5307 - Number.toFixed doesn't round 0.5 up
Summary: Number.toFixed doesn't round 0.5 up
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: Nobody
URL: javascript:alert((0.5).toFixed(0))
Keywords:
: 9550 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-10-09 11:32 PDT by Bob Ippolito
Modified: 2006-06-22 22:01 PDT (History)
1 user (show)

See Also:


Attachments
Patch for 5307, including test case (2.25 KB, patch)
2006-01-03 01:48 PST, Ricci Adams
ggaren: 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:32:24 PDT
Math.round() rounds 0.5 up, and (0.51).toFixed(0) rounds up, but (0.5).toFixed(0) does not.  This is 
inconsistent with other browsers and itself.
Comment 1 Ricci Adams 2006-01-03 01:48:43 PST
Created attachment 5444 [details]
Patch for 5307, including test case

From my interpretation (and Maciej's) of ECMA-262 Section 15.7.4.5, it looks
like step 10 means to round the number.  Hence, 0.5.toFixed(0) should indeed be
1.
Comment 2 Ricci Adams 2006-01-03 01:57:40 PST
Note: I do not believe that the summary for this bug is correct.  (0.51).toFixed() does round up to 1, it is 
only 0.5 that is (was) not working.  Hence, the summary should probably read "Number.toFixed doesn't 
round up for 0.5"
Comment 3 Geoffrey Garen 2006-01-03 09:25:31 PST
Comment on attachment 5444 [details]
Patch for 5307, including test case

r=me
Comment 4 Darin Adler 2006-01-06 09:34:22 PST
Should really put in a test for -0.5 too.
Comment 5 Alexey Proskuryakov 2006-06-22 22:01:03 PDT
*** Bug 9550 has been marked as a duplicate of this bug. ***