<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.strings.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.money-format.php',
    1 => 'money_format',
    2 => 'Formats a number as a currency string',
  ),
  'up' => 
  array (
    0 => 'ref.strings.php',
    1 => 'String Functions',
  ),
  'prev' => 
  array (
    0 => 'function.metaphone.php',
    1 => 'metaphone',
  ),
  'next' => 
  array (
    0 => 'function.nl-langinfo.php',
    1 => 'nl_langinfo',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/strings/functions/money-format.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.money-format" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">money_format</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">money_format</span> &mdash; <span class="dc-title">Formats a number as a currency string</span></p>

 </div>
 
 <div id="function.money-format-refsynopsisdiv">
   <div class="warning"><strong class="warning">Warning</strong><p class="simpara">This function has been
<em>DEPRECATED</em> as of PHP 7.4.0, and <em>REMOVED</em> as of PHP 8.0.0. Relying on this function
is highly discouraged.</p></div>
 </div>
 
 <div class="refsect1 description" id="refsect1-function.money-format-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>money_format</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$format</code></span>, <span class="methodparam"><span class="type"><a href="language.types.float.php" class="type float">float</a></span> <code class="parameter">$number</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>money_format()</strong></span> returns a formatted version of
   <code class="parameter">number</code>.  This function wraps the C library
   function <span class="function"><strong>strfmon()</strong></span>, with the difference that
   this implementation converts only one number at a time.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.money-format-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">format</code></dt>
     <dd>
      <p class="para">
       The format specification consists of the following sequence:
       <ul class="itemizedlist">
        <li class="listitem"><p class="para">a <code class="literal">%</code> character</p></li>
        <li class="listitem"><p class="para">optional flags</p></li>
        <li class="listitem"><p class="para">optional field width</p></li>
        <li class="listitem"><p class="para">optional left precision</p></li>
        <li class="listitem"><p class="para">optional right precision</p></li>
        <li class="listitem"><p class="para">a required conversion character</p></li>
       </ul>
      </p>
      <p class="formalpara">
       <h5 class="title">Flags</h5>
       <p class="para">
       One or more of the optional flags below can be used:
        <dl>
         
          <dt><code class="literal">=</code><span class="replaceable">f</span></dt>
          <dd>
           <p class="para">
            The character <code class="literal">=</code> followed by a (single byte)
            character <span class="replaceable">f</span> to be used as the numeric fill
            character. The default fill character is space.
           </p>
          </dd>
         
         
          <dt><code class="literal">^</code></dt>
          <dd>
           <p class="para">
            Disable the use of grouping characters (as defined
            by the current locale).
           </p>
          </dd>
         
         
          <dt><code class="literal">+</code> or <code class="literal">(</code></dt>
          <dd>
           <p class="para">
            Specify the formatting style for positive and negative numbers.
            If <code class="literal">+</code> is used, the locale&#039;s equivalent for
            <code class="literal">+</code> and <code class="literal">-</code> will be used. If
            <code class="literal">(</code> is used, negative amounts are enclosed in
            parenthesis. If no specification is given, the default is
            <code class="literal">+</code>.
           </p>
          </dd>
         
         
          <dt><code class="literal">!</code></dt>
          <dd>
           <p class="para">
            Suppress the currency symbol from the output string.
           </p>
          </dd>
         
         
          <dt><code class="literal">-</code></dt>
          <dd>
           <p class="para">
            If present, it will make all fields left-justified (padded to the
            right), as opposed to the default which is for the fields to be
            right-justified (padded to the left).
           </p>
          </dd>
         
        </dl>
       </p>
      </p>
      <p class="formalpara">
       <h5 class="title">Field width</h5>
       <p class="para">
        <dl>
         
          <dt><span class="replaceable">w</span></dt>
          <dd>
           <p class="para">
            A decimal digit string specifying a minimum field width. Field will
            be right-justified unless the flag <code class="literal">-</code> is used.
            Default value is 0 (zero).
           </p>
          </dd>
         
        </dl>
       </p>
      </p>
      <p class="formalpara">
       <h5 class="title">Left precision</h5>
       <p class="para">
        <dl>
         
          <dt><code class="literal">#</code><span class="replaceable">n</span></dt>
          <dd>
           <p class="para">
            The maximum number of digits (<span class="replaceable">n</span>) expected
            to the left of the decimal character (e.g. the decimal point). It is
            used usually to keep formatted output aligned in the same columns,
            using the fill character if the number of digits is less than
            <span class="replaceable">n</span>. If the number of actual digits is
            bigger than <span class="replaceable">n</span>, then this specification is
            ignored.
           </p>
           <p class="para">
            If grouping has not been suppressed using the <code class="literal">^</code>
            flag, grouping separators will be inserted before the fill
            characters (if any) are added. Grouping separators will not be
            applied to fill characters, even if the fill character is a digit.
           </p>
           <p class="para">
            To ensure alignment, any characters appearing before or after the
            number in the formatted output such as currency or sign symbols are
            padded as necessary with space characters to make their positive and
            negative formats an equal length.
           </p>
          </dd>
         
        </dl>
       </p>
      </p>
      <p class="formalpara">
       <h5 class="title">
        Right precision
       </h5>
       <p class="para">
        <dl>
         
          <dt><code class="literal">.</code><span class="replaceable">p</span></dt>
          <dd>
           <p class="para">
            A period followed by the number of digits
            (<span class="replaceable">p</span>) after the decimal character. If the
            value of <span class="replaceable">p</span> is 0 (zero), the decimal
            character and the digits to its right will be omitted. If no right
            precision is included, the default will dictated by the current
            locale in use. The amount being formatted is rounded to the specified
            number of digits prior to formatting.
           </p>
          </dd>
         
        </dl>
       </p>
      </p>
      <p class="formalpara">
       <h5 class="title">
        Conversion characters
       </h5>
       <p class="para">
        <dl>
         
          <dt><code class="literal">i</code></dt>
          <dd>
           <p class="para">
            The number is formatted according to the locale&#039;s international
            currency format (e.g. for the USA locale: USD 1,234.56).
           </p>
          </dd>
         
         
          <dt><code class="literal">n</code></dt>
          <dd>
           <p class="para">
            The number is formatted according to the locale&#039;s national
            currency format (e.g. for the de_DE locale: EU1.234,56).
           </p>
          </dd>
         
         
          <dt><code class="literal">%</code></dt>
          <dd>
           <p class="para">
            Returns the <code class="literal">%</code> character.
           </p>
          </dd>
         
        </dl>
       </p>
      </p>
     </dd>
    
    
     <dt><code class="parameter">number</code></dt>
     <dd>
      <p class="para">
       The number to be formatted.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.money-format-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the formatted string. Characters before and after the formatting
   string will be returned unchanged.
   Non-numeric <code class="parameter">number</code> causes returning <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> and
   emitting <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.money-format-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        Removed this function.
       </td>
      </tr>

      <tr>
       <td>7.4.0</td>
       <td>
        Deprecated this function. Instead, 
        use <span class="methodname"><a href="numberformatter.formatcurrency.php" class="methodname">NumberFormatter::formatCurrency()</a></span>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.money-format-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>money_format()</strong></span> Example</strong></p>
    <div class="example-contents"><p>
     We will use different locales and format specifications to
     illustrate the use of this function.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$number </span><span style="color: #007700">= </span><span style="color: #0000BB">1234.56</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// let's print the international format for the en_US locale<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_MONETARY</span><span style="color: #007700">, </span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">money_format</span><span style="color: #007700">(</span><span style="color: #DD0000">'%i'</span><span style="color: #007700">, </span><span style="color: #0000BB">$number</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// USD 1,234.56<br /><br />// Italian national format with 2 decimals`<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_MONETARY</span><span style="color: #007700">, </span><span style="color: #DD0000">'it_IT'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">money_format</span><span style="color: #007700">(</span><span style="color: #DD0000">'%.2n'</span><span style="color: #007700">, </span><span style="color: #0000BB">$number</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// Eu 1.234,56<br /><br />// Using a negative number<br /></span><span style="color: #0000BB">$number </span><span style="color: #007700">= -</span><span style="color: #0000BB">1234.5672</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// US national format, using () for negative numbers<br />// and 10 digits for left precision<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_MONETARY</span><span style="color: #007700">, </span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">money_format</span><span style="color: #007700">(</span><span style="color: #DD0000">'%(#10n'</span><span style="color: #007700">, </span><span style="color: #0000BB">$number</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// ($        1,234.57)<br /><br />// Similar format as above, adding the use of 2 digits of right<br />// precision and '*' as a fill character<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">money_format</span><span style="color: #007700">(</span><span style="color: #DD0000">'%=*(#10.2n'</span><span style="color: #007700">, </span><span style="color: #0000BB">$number</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// ($********1,234.57)<br /><br />// Let's justify to the left, with 14 positions of width, 8 digits of<br />// left precision, 2 of right precision, without the grouping character<br />// and using the international format for the de_DE locale.<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_MONETARY</span><span style="color: #007700">, </span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">money_format</span><span style="color: #007700">(</span><span style="color: #DD0000">'%=*^-14#8.2i'</span><span style="color: #007700">, </span><span style="color: #0000BB">1234.56</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// Eu 1234,56****<br /><br />// Let's add some blurb before and after the conversion specification<br /></span><span style="color: #0000BB">setlocale</span><span style="color: #007700">(</span><span style="color: #0000BB">LC_MONETARY</span><span style="color: #007700">, </span><span style="color: #DD0000">'en_GB'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fmt </span><span style="color: #007700">= </span><span style="color: #DD0000">'The final value is %i (after a 10%% discount)'</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">money_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">, </span><span style="color: #0000BB">1234.56</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">// The final value is  GBP 1,234.56 (after a 10% discount)<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.money-format-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    The function <span class="function"><strong>money_format()</strong></span> is only defined if
    the system has strfmon capabilities.  For example, Windows does
    not, so <span class="function"><strong>money_format()</strong></span> is undefined in Windows.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    The <strong><code><a href="string.constants.php#constant.lc-monetary">LC_MONETARY</a></code></strong> category of the locale settings,
    affects the behavior of this function. Use <span class="function"><a href="function.setlocale.php" class="function">setlocale()</a></span>
    to set to the appropriate default locale before using this function.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.money-format-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.setlocale.php" class="function" rel="rdfs-seeAlso">setlocale()</a> - Set locale information</span></li>
    <li><span class="function"><a href="function.sscanf.php" class="function" rel="rdfs-seeAlso">sscanf()</a> - Parses input from a string according to a format</span></li>
    <li><span class="function"><a href="function.sprintf.php" class="function" rel="rdfs-seeAlso">sprintf()</a> - Return a formatted string</span></li>
    <li><span class="function"><a href="function.printf.php" class="function" rel="rdfs-seeAlso">printf()</a> - Output a formatted string</span></li>
    <li><span class="function"><a href="function.number-format.php" class="function" rel="rdfs-seeAlso">number_format()</a> - Format a number with grouped thousands</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>