<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="floating-point-types">
      </a>
      13.1.4 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE
     </h3>
    </div>
   </div>
  </div>
  <p>
   The
   <code class="literal">
    FLOAT
   </code>
   and
   <code class="literal">
    DOUBLE
   </code>
   types
        represent approximate numeric data values. MySQL uses four bytes
        for single-precision values and eight bytes for double-precision
        values.
  </p>
  <p>
   For
   <code class="literal">
    FLOAT
   </code>
   , the SQL standard permits an
        optional specification of the precision (but not the range of
        the exponent) in bits following the keyword
   <code class="literal">
    FLOAT
   </code>
   in parentheses, that is,
   <a class="link" href="floating-point-types.html" title="13.1.4 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE">
    <code class="literal">
     FLOAT(
     <em class="replaceable">
      <code>
       p
      </code>
     </em>
     )
    </code>
   </a>
   .
        MySQL also supports this optional precision specification, but
        the precision value in
   <a class="link" href="floating-point-types.html" title="13.1.4 Floating-Point Types (Approximate Value) - FLOAT, DOUBLE">
    <code class="literal">
     FLOAT(
     <em class="replaceable">
      <code>
       p
      </code>
     </em>
     )
    </code>
   </a>
   is used only to determine storage size. A precision from 0 to 23
        results in a 4-byte single-precision
   <code class="literal">
    FLOAT
   </code>
   column. A precision from 24 to 53 results in an 8-byte
        double-precision
   <code class="literal">
    DOUBLE
   </code>
   column.
  </p>
  <p>
   MySQL permits a nonstandard syntax:
   <code class="literal">
    FLOAT(
    <em class="replaceable">
     <code>
      M
     </code>
    </em>
    ,
    <em class="replaceable">
     <code>
      D
     </code>
    </em>
    )
   </code>
   or
   <code class="literal">
    REAL(
    <em class="replaceable">
     <code>
      M
     </code>
    </em>
    ,
    <em class="replaceable">
     <code>
      D
     </code>
    </em>
    )
   </code>
   or
   <code class="literal">
    DOUBLE
        PRECISION(
    <em class="replaceable">
     <code>
      M
     </code>
    </em>
    ,
    <em class="replaceable">
     <code>
      D
     </code>
    </em>
    )
   </code>
   .
        Here,
   <code class="literal">
    (
    <em class="replaceable">
     <code>
      M
     </code>
    </em>
    ,
    <em class="replaceable">
     <code>
      D
     </code>
    </em>
    )
   </code>
   means than values can be stored with up to
   <em class="replaceable">
    <code>
     M
    </code>
   </em>
   digits in total, of which
   <em class="replaceable">
    <code>
     D
    </code>
   </em>
   digits may be after the decimal
        point. For example, a column defined as
   <code class="literal">
    FLOAT(7,4)
   </code>
   is displayed as
   <code class="literal">
    -999.9999
   </code>
   . MySQL performs rounding when
        storing values, so if you insert
   <code class="literal">
    999.00009
   </code>
   into a
   <code class="literal">
    FLOAT(7,4)
   </code>
   column, the approximate
        result is
   <code class="literal">
    999.0001
   </code>
   .
  </p>
  <p>
   <code class="literal">
    FLOAT(
    <em class="replaceable">
     <code>
      M
     </code>
    </em>
    ,
    <em class="replaceable">
     <code>
      D
     </code>
    </em>
    )
   </code>
   and
   <code class="literal">
    DOUBLE(
    <em class="replaceable">
     <code>
      M
     </code>
    </em>
    ,
    <em class="replaceable">
     <code>
      D
     </code>
    </em>
    )
   </code>
   are nonstandard MySQL extensions; and are deprecated. You should
        expect support for these variants to be removed in a future
        version of MySQL.
  </p>
  <p>
   Because floating-point values are approximate and not stored as
        exact values, attempts to treat them as exact in comparisons may
        lead to problems. They are also subject to platform or
        implementation dependencies. For more information, see
   <a class="xref" href="problems-with-float.html" title="B.3.4.8 Problems with Floating-Point Values">
    Section B.3.4.8, “Problems with Floating-Point Values”
   </a>
   .
  </p>
  <p>
   For maximum portability, code requiring storage of approximate
        numeric data values should use
   <code class="literal">
    FLOAT
   </code>
   or
   <code class="literal">
    DOUBLE PRECISION
   </code>
   with no specification of
        precision or number of digits.
  </p>
 </div>
 <br/>
</div>
