<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>9550</bug_id>
          
          <creation_ts>2006-06-22 17:04:29 -0700</creation_ts>
          <short_desc>Different rounding behaviors of toFixed</short_desc>
          <delta_ts>2006-06-22 22:01:03 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>417.x</version>
          <rep_platform>PC</rep_platform>
          <op_sys>OS X 10.4</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>5307</dup_id>
          
          <bug_file_loc>javascript:alert(0.055.toFixed(2))</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="yz">fick_el</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>46754</commentid>
    <comment_count>0</comment_count>
    <who name="yz">fick_el</who>
    <bug_when>2006-06-22 17:04:29 -0700</bug_when>
    <thetext>toFixed(n) will round to the nearest number with n digits, however inconsistencies begin to occur when the number is exactly halfway between two possible results.

When it is halfway the &quot;standard&quot; behavior is to round away from zero (up in a positive number, down in a negative one). ECMA-262, being based on IEEE 754, cannot truly represent some numbers (such as 0.045), so they are being rounded to 0.04:

Using 0.045.toFixed(2) Safari &quot;gets it right&quot;, assuming IEEE 754 number representation:
SAFARI: 0.04
IE7: 0.05
FF: 0.04
OP9: 0.04
KONQUEROR: 0.04
MINEFIELD: 0.04
ICAB: 0.05

However, using 0.055.toFixed(2) Safari is pretty much the odd browser out (0.05 instead of 0.06):
SAFARI: 0.05
IE7: 0.06
FF: 0.06
OP9: 0.06
KONQUEROR: 0.06
MINEFIELD: 0.06
ICAB: 0.06

So IE (and ICAB?) &quot;correctly&quot; round up regardless of IEEE 754 binary representation, FF/OP/KONQ round up based on IEEE 754, so naturally they all make the same consistent &quot;mistakes&quot;. But Safari&apos;s results are sometimes inconsistent with those of others based on IEEE 754.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>46762</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2006-06-22 22:01:03 -0700</bug_when>
    <thetext>I cannot reproduce this problem with current WebKit (http://nightly.webkit.org&gt;. Most likely, fixed in bug 5307.

*** This bug has been marked as a duplicate of 5307 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>