Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > a34ed6838d4b29d38abd504392a4a797 > files > 1556

php-manual-es-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>money_format</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Manual de PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Funciones de cadenas"
HREF="ref.strings.html"><LINK
REL="PREVIOUS"
TITLE="metaphone"
HREF="function.metaphone.html"><LINK
REL="NEXT"
TITLE="nl_langinfo"
HREF="function.nl-langinfo.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual de PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.metaphone.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.nl-langinfo.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.money-format"
></A
>money_format</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN74997"
></A
><P
>    (PHP 4 &#62;= 4.3.0)</P
>money_format&nbsp;--&nbsp;Formats a number as a currency string</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN75000"
></A
><H2
>Description</H2
>string <B
CLASS="methodname"
>money_format</B
> ( string format, float number)<BR
></BR
><P
>&#13;     <B
CLASS="function"
>money_format()</B
> returns a formatted version of
     <TT
CLASS="parameter"
><I
>number</I
></TT
>.  This function wraps the C library
     function <B
CLASS="function"
>strfmon()</B
>, with the difference that
     this implementation converts only one number at a time.
    </P
><P
>&#13;     The format specification consists of the following sequence:
     <P
></P
><UL
><LI
><P
>a <TT
CLASS="literal"
>%</TT
> character</P
></LI
><LI
><P
>optional flags</P
></LI
><LI
><P
>optional field width</P
></LI
><LI
><P
>optional left precision</P
></LI
><LI
><P
>optional right precision</P
></LI
><LI
><P
>a required conversion character</P
></LI
></UL
>
    </P
><DIV
CLASS="formalpara"
><P
><B
>Flags. </B
>
     One or more of the optional flags below can be used:
      <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="literal"
>=</TT
><TT
CLASS="replaceable"
><I
>f</I
></TT
></DT
><DD
><P
>&#13;          The character <TT
CLASS="literal"
>=</TT
> followed by a a (single byte)
          character <TT
CLASS="replaceable"
><I
>f</I
></TT
> to be used as the numeric fill
          character. The default fill character is space.
         </P
></DD
><DT
><TT
CLASS="literal"
>^</TT
></DT
><DD
><P
>&#13;          Disable the use of grouping characters (as defined
          by the current locale).
         </P
></DD
><DT
><TT
CLASS="literal"
>+</TT
> or <TT
CLASS="literal"
>(</TT
></DT
><DD
><P
>&#13;          Specify the formatting style for positive and negative numbers.
          If <TT
CLASS="literal"
>+</TT
> is used, the locale's equivalent for
          <TT
CLASS="literal"
>+</TT
> and <TT
CLASS="literal"
>-</TT
> will be used. If
          <TT
CLASS="literal"
>(</TT
> is used, negative amounts are enclosed in
          parenthesis. If no specification is given, the default is
          <TT
CLASS="literal"
>+</TT
>.
         </P
></DD
><DT
><TT
CLASS="literal"
>!</TT
></DT
><DD
><P
>&#13;          Suppress the currency symbol from the output string.
         </P
></DD
><DT
><TT
CLASS="literal"
>-</TT
></DT
><DD
><P
>&#13;          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
></DIV
>
     </P
></DIV
><DIV
CLASS="formalpara"
><P
><B
>Field width. </B
>
      <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="replaceable"
><I
>w</I
></TT
></DT
><DD
><P
>&#13;          A decimal digit string specifying a minimum field width. Field will
          be right-justified unless the flag <TT
CLASS="literal"
>-</TT
> is used.
          Default value is 0 (zero).
         </P
></DD
></DL
></DIV
>
     </P
></DIV
><DIV
CLASS="formalpara"
><P
><B
>Left precision. </B
>
      <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="literal"
>#</TT
><TT
CLASS="replaceable"
><I
>n</I
></TT
></DT
><DD
><P
>&#13;          The maximum number of digits (<TT
CLASS="replaceable"
><I
>n</I
></TT
>) 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
          <TT
CLASS="replaceable"
><I
>n</I
></TT
>. If the number of actual digits is
          bigger than <TT
CLASS="replaceable"
><I
>n</I
></TT
>, then this specification is
          ignored.
         </P
><P
>&#13;          If grouping has not been suppressed using the <TT
CLASS="literal"
>^</TT
>
          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
>&#13;          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
></DIV
>
     </P
></DIV
><DIV
CLASS="formalpara"
><P
><B
>&#13;      Right precision
     . </B
>
      <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="literal"
>.</TT
><TT
CLASS="replaceable"
><I
>p</I
></TT
></DT
><DD
><P
>&#13;          A period followed by the number of digits
          (<TT
CLASS="replaceable"
><I
>p</I
></TT
>) after the decimal character. If the
          value of <TT
CLASS="replaceable"
><I
>p</I
></TT
> 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
          local in use. The amount being formatted is rounded to the specified 
          number of digits prior to formatting.
         </P
></DD
></DL
></DIV
>
     </P
></DIV
><DIV
CLASS="formalpara"
><P
><B
>&#13;      Conversion characters
     . </B
>
      <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="literal"
>i</TT
></DT
><DD
><P
>&#13;          The number is formatted according to the locale's international
          currency format (e.g. for the USA locale: USD 1,234.56).
         </P
></DD
><DT
><TT
CLASS="literal"
>n</TT
></DT
><DD
><P
>&#13;          The number is formatted according to the locale's national
          currency format (e.g. for the de_DE locale: DM1.234,56).
         </P
></DD
><DT
><TT
CLASS="literal"
>%</TT
></DT
><DD
><P
>&#13;          Returns the the <TT
CLASS="literal"
>%</TT
> character.
         </P
></DD
></DL
></DIV
>
     </P
></DIV
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
      The <TT
CLASS="constant"
><B
>LC_MONETARY</B
></TT
> category of the locale settings,
      affects the behavior of this function. Use
      <A
HREF="function.setlocale.html"
><B
CLASS="function"
>setlocale()</B
></A
> to set to the appropriate default locale
      before using this function.
     </P
><P
>&#13;      Characters before and after the formatting string will be returned
      unchanged.
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;    <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN75132"
></A
><P
><B
>Ejemplo 1. <B
CLASS="function"
>money_format()</B
> Example</B
></P
><P
>&#13;      We will use different locales and format specifications to
      illustrate the use of this function.
     </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php

    $number = 1234.56;

    // let's print the international format for the en_US locale
    setlocale(LC_MONETARY, 'en_US');
    echo money_format('%i', $number)."\n";
    // USD 1,234.56

    // Italian national format with 2 decimals`
    setlocale(LC_MONETARY, 'it_IT');
    echo money_format('%.2n', $number)."\n";
    // L. 1.234,56

    // Using a negative number
    $number = -1234.5672;

    // US national format, using () for negative numbers
    // and 10 digits for left precision
    setlocale(LC_MONETARY, 'en_US');
    echo money_format('%(#10n', $number)."\n";
    // ($        1,234.57)

    // Similar format as above, adding the use of 2 digits of right 
    // precision and '*' as a fill character
    echo money_format('%=*(#10.2n', $number)."\n";
    // ($********1,234.57)
    
    // Let's justify to the left, with 14 positions of width, 8 digits of
    // left precision, 2 of right precision, withouth grouping character
    // and using the international format for the de_DE locale.
    setlocale(LC_MONETARY, 'de_DE');
    echo money_format('%=*^-14#8.2i', 1234.56)."\n";
    // DEM 1234,56****

    // Let's add some blurb before and after the conversion specification
    setlocale(LC_MONETARY, 'en_GB');
    $fmt = 'The final value is %i (after a 10%% discount)';
    echo money_format($fmt, 1234.56)."\n";
    // The final value is  GBP 1,234.56 (after a 10% discount)

?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     See also: <A
HREF="function.setlocale.html"
><B
CLASS="function"
>setlocale()</B
></A
>,
     <A
HREF="function.number-format.html"
><B
CLASS="function"
>number_format()</B
></A
>,<A
HREF="function.sprintf.html"
><B
CLASS="function"
>sprintf()</B
></A
>,
     <A
HREF="function.printf.html"
><B
CLASS="function"
>printf()</B
></A
> and <A
HREF="function.sscanf.html"
><B
CLASS="function"
>sscanf()</B
></A
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.metaphone.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Inicio</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.nl-langinfo.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>metaphone</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.strings.html"
ACCESSKEY="U"
>Subir</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>nl_langinfo</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>