Bug 24711 - 1.95.toFixed(1) should equal "1.9" but does not
Summary: 1.95.toFixed(1) should equal "1.9" but does not
Status: RESOLVED DUPLICATE of bug 44745
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL: javascript: alert(1.95.toFixed(1) ===...
Keywords: HasReduction, InRadar
: 31777 (view as bug list)
Depends on:
Reported: 2009-03-19 19:48 PDT by Jeff Walden (remove +bwo to email)
Modified: 2010-08-27 12:56 PDT (History)
8 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Walden (remove +bwo to email) 2009-03-19 19:48:20 PDT

This is reproducible in Safari 4 beta on 10.4 (r41760) and on Windows XP (just 4b).  May you have as much pleasure dealing with this as I did in (incorrectly) checking SpiderMonkey's behavior, because it would be the height of unfairness for me to hog all the fun.  :-)
Comment 1 Mark Rowe (bdash) 2009-03-19 23:33:49 PDT
Comment 2 Cameron Zwarich (cpst) 2009-03-20 01:10:09 PDT
I don't understand why 1.9 is the correct value. The ECMA spec gives an algorithm for toFixed in This algorithm is copied almost literally by the implementation in JavaScriptCore. I'll double check this case by hand.
Comment 3 Jeff Walden (remove +bwo to email) 2009-03-20 01:18:11 PDT
Cameron, see the Mozilla bug, it's all calculated by hand there -- just the problem of a flipped equality.  But if you do feel like running it out by hand, by all means feel free, because you'll get an even better idea of how much fun can be had here.
Comment 4 Alexey Proskuryakov 2009-03-20 01:22:34 PDT
See also: bug 16651, bug 16653.
Comment 5 Cameron Zwarich (cpst) 2009-03-20 02:23:51 PDT
Okay, I see our mistake. This will be a bit of work to fix. There may be similar problems in other places.
Comment 6 bugzilla33 2009-11-22 01:06:45 PST
toFixed rounds, not floors !
bug 24711 is not a Bug !!

(1.95) . toFixed( 1 ) = 2.0


Math.round ( 1.95 * 10 ) / 10
equal 2
Comment 7 bugzilla33 2009-11-22 01:16:04 PST
Not a Bug.
All browsers before returns string value (IE, Opera, Konqueror, Chrome, Firefox) rounding a Number to defined scale.
Comment 8 Gavin Barraclough 2010-08-27 12:48:23 PDT
For a simpler explanation of why this is a valid bug, try:

(but! this also doesn't work in ToT!) - the correct result should be 1.94999999999999995559.

Since the precise mathematical value passed to toFixed is closer to 1.9 than 2.0, 1.9 is the correct result.

This should be fixed by https://bugs.webkit.org/show_bug.cgi?id=44745

*** This bug has been marked as a duplicate of bug 44745 ***
Comment 9 Gavin Barraclough 2010-08-27 12:56:54 PDT
*** Bug 31777 has been marked as a duplicate of this bug. ***