<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="precision-math">
      </a>
      14.24 Precision Math
     </h2>
    </div>
   </div>
  </div>
  <div class="toc">
   <dl class="toc">
    <dt>
     <span class="section">
      <a href="precision-math-numbers.html">
       14.24.1 Types of Numeric Values
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="precision-math-decimal-characteristics.html">
       14.24.2 DECIMAL Data Type Characteristics
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="precision-math-expressions.html">
       14.24.3 Expression Handling
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="precision-math-rounding.html">
       14.24.4 Rounding Behavior
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="precision-math-examples.html">
       14.24.5 Precision Math Examples
      </a>
     </span>
    </dt>
   </dl>
  </div>
  <a class="indexterm" name="idm46045190531376">
  </a>
  <a class="indexterm" name="idm46045190530304">
  </a>
  <a class="indexterm" name="idm46045190529232">
  </a>
  <a class="indexterm" name="idm46045190528160">
  </a>
  <a class="indexterm" name="idm46045190527088">
  </a>
  <a class="indexterm" name="idm46045190526016">
  </a>
  <a class="indexterm" name="idm46045190524944">
  </a>
  <a class="indexterm" name="idm46045190523456">
  </a>
  <a class="indexterm" name="idm46045190521968">
  </a>
  <a class="indexterm" name="idm46045190520896">
  </a>
  <a class="indexterm" name="idm46045190519808">
  </a>
  <a class="indexterm" name="idm46045190518736">
  </a>
  <p>
   MySQL provides support for precision math: numeric value handling
    that results in extremely accurate results and a high degree control
    over invalid values. Precision math is based on these two features:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      SQL modes that control how strict the server is about accepting
        or rejecting invalid data.
     </p>
    </li>
    <li class="listitem">
     <p>
      The MySQL library for fixed-point arithmetic.
     </p>
    </li>
   </ul>
  </div>
  <p>
   These features have several implications for numeric operations and
    provide a high degree of compliance with standard SQL:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <span class="bold">
       <strong>
        Precise calculations
       </strong>
      </span>
      : For
        exact-value numbers, calculations do not introduce
        floating-point errors. Instead, exact precision is used. For
        example, MySQL treats a number such as
      <code class="literal">
       .0001
      </code>
      as an exact value rather than as an approximation, and summing
        it 10,000 times produces a result of exactly
      <code class="literal">
       1
      </code>
      , not a value that is merely
      <span class="quote">
       “
       <span class="quote">
        close
       </span>
       ”
      </span>
      to 1.
     </p>
    </li>
    <li class="listitem">
     <p>
      <span class="bold">
       <strong>
        Well-defined rounding behavior
       </strong>
      </span>
      :
        For exact-value numbers, the result of
      <a class="link" href="mathematical-functions.html#function_round">
       <code class="literal">
        ROUND()
       </code>
      </a>
      depends on its argument,
        not on environmental factors such as how the underlying C
        library works.
     </p>
    </li>
    <li class="listitem">
     <p>
      <span class="bold">
       <strong>
        Platform independence
       </strong>
      </span>
      :
        Operations on exact numeric values are the same across different
        platforms such as Windows and Unix.
     </p>
    </li>
    <li class="listitem">
     <p>
      <span class="bold">
       <strong>
        Control over handling of invalid
        values
       </strong>
      </span>
      : Overflow and division by zero are detectable
        and can be treated as errors. For example, you can treat a value
        that is too large for a column as an error rather than having
        the value truncated to lie within the range of the column's data
        type. Similarly, you can treat division by zero as an error
        rather than as an operation that produces a result of
      <code class="literal">
       NULL
      </code>
      . The choice of which approach to take is
        determined by the setting of the server SQL mode.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The following discussion covers several aspects of how precision
    math works, including possible incompatibilities with older
    applications. At the end, some examples are given that demonstrate
    how MySQL handles numeric operations precisely. For information
    about controlling the SQL mode, see
   <a class="xref" href="sql-mode.html" title="7.1.11 Server SQL Modes">
    Section 7.1.11, “Server SQL Modes”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
