<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="fixed-point-types">
      </a>
      13.1.3 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC
     </h3>
    </div>
   </div>
  </div>
  <p>
   The
   <code class="literal">
    DECIMAL
   </code>
   and
   <code class="literal">
    NUMERIC
   </code>
   types store exact numeric data values. These types are used when
        it is important to preserve exact precision, for example with
        monetary data. In MySQL,
   <code class="literal">
    NUMERIC
   </code>
   is
        implemented as
   <code class="literal">
    DECIMAL
   </code>
   , so the following
        remarks about
   <code class="literal">
    DECIMAL
   </code>
   apply equally to
   <code class="literal">
    NUMERIC
   </code>
   .
  </p>
  <p>
   MySQL stores
   <code class="literal">
    DECIMAL
   </code>
   values in binary format.
        See
   <a class="xref" href="precision-math.html" title="14.24 Precision Math">
    Section 14.24, “Precision Math”
   </a>
   .
  </p>
  <p>
   In a
   <code class="literal">
    DECIMAL
   </code>
   column declaration, the
        precision and scale can be (and usually is) specified. For
        example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa56413198"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-sql">salary <span class="token datatype">DECIMAL</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">)</span></code></pre>
  </div>
  <p>
   In this example,
   <code class="literal">
    5
   </code>
   is the precision and
   <code class="literal">
    2
   </code>
   is the scale. The precision represents the
        number of significant digits that are stored for values, and the
        scale represents the number of digits that can be stored
        following the decimal point.
  </p>
  <p>
   Standard SQL requires that
   <code class="literal">
    DECIMAL(5,2)
   </code>
   be
        able to store any value with five digits and two decimals, so
        values that can be stored in the
   <code class="literal">
    salary
   </code>
   column range from
   <code class="literal">
    -999.99
   </code>
   to
   <code class="literal">
    999.99
   </code>
   .
  </p>
  <p>
   In standard SQL, the syntax
   <code class="literal">
    DECIMAL(
    <em class="replaceable">
     <code>
      M
     </code>
    </em>
    )
   </code>
   is
        equivalent to
   <code class="literal">
    DECIMAL(
    <em class="replaceable">
     <code>
      M
     </code>
    </em>
    ,0)
   </code>
   .
        Similarly, the syntax
   <code class="literal">
    DECIMAL
   </code>
   is equivalent
        to
   <code class="literal">
    DECIMAL(
    <em class="replaceable">
     <code>
      M
     </code>
    </em>
    ,0)
   </code>
   ,
        where the implementation is permitted to decide the value of
   <em class="replaceable">
    <code>
     M
    </code>
   </em>
   . MySQL supports both of these
        variant forms of
   <code class="literal">
    DECIMAL
   </code>
   syntax. The default
        value of
   <em class="replaceable">
    <code>
     M
    </code>
   </em>
   is 10.
  </p>
  <p>
   If the scale is 0,
   <code class="literal">
    DECIMAL
   </code>
   values contain no
        decimal point or fractional part.
  </p>
  <p>
   The maximum number of digits for
   <code class="literal">
    DECIMAL
   </code>
   is
        65, but the actual range for a given
   <code class="literal">
    DECIMAL
   </code>
   column can be constrained by the precision or scale for a given
        column. When such a column is assigned a value with more digits
        following the decimal point than are permitted by the specified
        scale, the value is converted to that scale. (The precise
        behavior is operating system-specific, but generally the effect
        is truncation to the permissible number of digits.)
  </p>
 </div>
 <br/>
</div>
