RESOLVED DUPLICATE of bug 44745 24711
1.95.toFixed(1) should equal "1.9" but does not
https://bugs.webkit.org/show_bug.cgi?id=24711
Summary 1.95.toFixed(1) should equal "1.9" but does not
Jeff Walden (remove +bwo to email)
Reported 2009-03-19 19:48:20 PDT
https://bugzilla.mozilla.org/show_bug.cgi?id=484293 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. :-)
Attachments
Mark Rowe (bdash)
Comment 1 2009-03-19 23:33:49 PDT
Cameron Zwarich (cpst)
Comment 2 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 15.7.4.5. This algorithm is copied almost literally by the implementation in JavaScriptCore. I'll double check this case by hand.
Jeff Walden (remove +bwo to email)
Comment 3 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.
Alexey Proskuryakov
Comment 4 2009-03-20 01:22:34 PDT
See also: bug 16651, bug 16653.
Cameron Zwarich (cpst)
Comment 5 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.
bugzilla33
Comment 6 2009-11-22 01:06:45 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
bugzilla33
Comment 7 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.
Gavin Barraclough
Comment 8 2010-08-27 12:48:23 PDT
For a simpler explanation of why this is a valid bug, try: javascript:alert((1.95).toPrecision(21)) (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 ***
Gavin Barraclough
Comment 9 2010-08-27 12:56:54 PDT
*** Bug 31777 has been marked as a duplicate of this bug. ***
Note You need to log in before you can comment on or make changes to this bug.