php-doc-en/reference/strings/functions/number-format.xml
2012-02-28 09:55:32 +00:00

189 lines
5.1 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.number-format" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>number_format</refname>
<refpurpose>Format a number with grouped thousands</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>number_format</methodname>
<methodparam><type>float</type><parameter>number</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>decimals</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<methodsynopsis>
<type>string</type><methodname>number_format</methodname>
<methodparam><type>float</type><parameter>number</parameter></methodparam>
<methodparam><type>int</type><parameter>decimals</parameter><initializer>0</initializer></methodparam>
<methodparam><type>string</type><parameter>dec_point</parameter><initializer>'.'</initializer></methodparam>
<methodparam><type>string</type><parameter>thousands_sep</parameter><initializer>','</initializer></methodparam>
</methodsynopsis>
<para>
This function accepts either one, two, or four parameters (not three):
</para>
<para>
If only one parameter is given,
<parameter>number</parameter> will be formatted without decimals,
but with a comma (",") between every group of thousands.
</para>
<para>
If two parameters are given, <parameter>number</parameter> will
be formatted with <parameter>decimals</parameter> decimals with a
dot (".") in front, and a comma (",") between every group of
thousands.
</para>
<para>
If all four parameters are given, <parameter>number</parameter>
will be formatted with <parameter>decimals</parameter> decimals,
<parameter>dec_point</parameter> instead of a dot (".") before
the decimals and <parameter>thousands_sep</parameter> instead of
a comma (",") between every group of thousands.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>number</parameter></term>
<listitem>
<para>
The number being formatted.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>decimals</parameter></term>
<listitem>
<para>
Sets the number of decimal points.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>dec_point</parameter></term>
<listitem>
<para>
Sets the separator for the decimal point.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>thousands_sep</parameter></term>
<listitem>
<para>
Sets the thousands separator.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
A formatted version of <parameter>number</parameter>.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.4.0</entry>
<entry>
This function now supports multiple bytes in
<parameter>dec_point</parameter> and
<parameter>thousands_sep</parameter>. Only the first byte of each
separator was used in older versions.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>number_format</function> Example</title>
<para>
For instance, French notation usually use two decimals,
comma (',') as decimal separator, and space (' ') as
thousand separator. This is achieved with this line :
</para>
<programlisting role="php">
<![CDATA[
<?php
$number = 1234.56;
// english notation (default)
$english_format_number = number_format($number);
// 1,235
// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56
$number = 1234.5678;
// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>money_format</function></member>
<member><function>sprintf</function></member>
<member><function>printf</function></member>
<member><function>sscanf</function></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->