Bug 31777 - Number.toFixed returns wrong values
Summary: Number.toFixed returns wrong values
Status: RESOLVED DUPLICATE of bug 24711
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows 7
: P2 Major
Assignee: Nobody
URL: http://pc44.one.pl/goorol/bugs/chrome...
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-21 16:50 PST by bugzilla33
Modified: 2010-08-27 12:56 PDT (History)
1 user (show)

See Also:


Attachments
source (1.48 KB, text/html)
2009-11-21 16:50 PST, bugzilla33
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description bugzilla33 2009-11-21 16:50:01 PST
Created attachment 43667 [details]
source

Number.toFixed returns sometimes wrong values (incorect rounding).

Please run attachment.


Actual Results:  

( 0.95 ) . toFixed ( 1 ) = 0.9
THOUGH
( 9.5 ) . toFixed ( 0 ) = 10


Expected Results:  

( 0.95 ) . toFixed ( 1 ) = 1.0
LIKE
( 9.5 ) . toFixed ( 0 ) = 10
Comment 1 Alexey Proskuryakov 2009-11-21 22:55:08 PST
Duplicate of bug 24711?
Comment 2 bugzilla33 2009-11-22 01:06:09 PST
toFixed rounds, not floors !
bug 24711 is not a Bug !!

(1.95) . toFixed( 1 ) = 2.0

because:

Math.round ( 1.95 * 10 ) / 10
equal 2
Comment 3 bugzilla33 2009-11-22 01:14:34 PST
All browsers before returns string value (IE, Opera, Konqueror, Chrome, Firefox) rounding a Number.
Comment 4 Gavin Barraclough 2010-08-27 12:56:54 PDT
yep, this is a dupe.

ieee754(.95) < decimal(.95), hence rounds up to 0.9 (ecma-262 15.7.4.5 requires we select the nearest value).
ieee754(9.5) == decimal(9.5), hence rounds up to 10 (ecma-262 15.7.4.5 requires we select the larger to two equally near values).

*** This bug has been marked as a duplicate of bug 24711 ***