2007-12-07 01:18:14 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 09:08:43 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-12-07 01:18:14 +00:00
|
|
|
<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>
|
2010-09-22 16:02:02 +00:00
|
|
|
<methodparam choice="opt"><type>int</type><parameter>decimals</parameter><initializer>0</initializer></methodparam>
|
2009-01-18 10:37:31 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<methodsynopsis>
|
|
|
|
<type>string</type><methodname>number_format</methodname>
|
|
|
|
<methodparam><type>float</type><parameter>number</parameter></methodparam>
|
2010-09-22 16:02:02 +00:00
|
|
|
<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>
|
2007-12-07 01:18:14 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2008-05-21 21:13:53 +00:00
|
|
|
This function accepts either one, two, or four parameters (not three):
|
2007-12-07 01:18:14 +00:00
|
|
|
</para>
|
2008-05-21 21:13:53 +00:00
|
|
|
<para>
|
|
|
|
If only one parameter is given,
|
2007-12-07 01:18:14 +00:00
|
|
|
<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>
|
|
|
|
|
2008-05-21 21:13:53 +00:00
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
|
|
|
<para>
|
|
|
|
A formatted version of <parameter>number</parameter>.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
2007-12-07 01:18:14 +00:00
|
|
|
<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>
|
2003-06-16 10:44:57 +00:00
|
|
|
<para>
|
2007-12-07 01:18:14 +00:00
|
|
|
Sets the number of decimal points.
|
2003-06-16 10:44:57 +00:00
|
|
|
</para>
|
2007-12-07 01:18:14 +00:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>dec_point</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the separator for the decimal point.
|
|
|
|
</para>
|
2010-11-07 04:11:27 +00:00
|
|
|
<para>
|
|
|
|
This function only takes the first byte for the
|
|
|
|
separator. This means that multibyte characters will
|
|
|
|
<emphasis>NOT</emphasis> work, resulting in a broken multibyte
|
|
|
|
sequence.
|
|
|
|
</para>
|
2007-12-07 01:18:14 +00:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>thousands_sep</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the thousands separator.
|
|
|
|
</para>
|
|
|
|
<para>
|
2010-10-22 02:05:08 +00:00
|
|
|
Only the first byte of <parameter>thousands_sep</parameter>
|
2010-09-24 05:12:09 +00:00
|
|
|
is used. For example, if you use <literal>&amp;</literal> as
|
2007-12-07 01:18:14 +00:00
|
|
|
<parameter>thousands_sep</parameter> on the number
|
|
|
|
<literal>1000</literal>, <function>number_format</function> will
|
2010-09-24 05:12:09 +00:00
|
|
|
return <literal>1&000</literal>.
|
2007-12-07 01:18:14 +00:00
|
|
|
</para>
|
2010-10-22 02:05:08 +00:00
|
|
|
<para>
|
2010-11-07 04:11:27 +00:00
|
|
|
As noted above in the description of the <parameter>dec_point</parameter>
|
|
|
|
parameter, then this function is not multibyte aware so using multibyte
|
|
|
|
characters as separators will result in broken sequences.
|
2010-10-22 02:05:08 +00:00
|
|
|
</para>
|
2007-12-07 01:18:14 +00:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</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">
|
2002-09-28 20:56:46 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
|
2003-05-30 16:36:18 +00:00
|
|
|
$number = 1234.56;
|
2002-09-28 20:56:46 +00:00
|
|
|
|
2003-05-30 16:36:18 +00:00
|
|
|
// english notation (default)
|
|
|
|
$english_format_number = number_format($number);
|
2005-05-23 10:54:59 +00:00
|
|
|
// 1,235
|
2002-09-28 20:56:46 +00:00
|
|
|
|
2003-05-30 16:36:18 +00:00
|
|
|
// French notation
|
|
|
|
$nombre_format_francais = number_format($number, 2, ',', ' ');
|
|
|
|
// 1 234,56
|
2002-09-28 20:56:46 +00:00
|
|
|
|
2003-05-30 16:36:18 +00:00
|
|
|
$number = 1234.5678;
|
2002-09-28 20:56:46 +00:00
|
|
|
|
2003-05-30 16:36:18 +00:00
|
|
|
// english notation without thousands seperator
|
|
|
|
$english_format_number = number_format($number, 2, '.', '');
|
|
|
|
// 1234.57
|
2002-09-28 20:56:46 +00:00
|
|
|
|
|
|
|
?>
|
|
|
|
]]>
|
2007-12-07 01:18:14 +00:00
|
|
|
</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>
|
2002-09-28 20:56:46 +00:00
|
|
|
|
2007-12-07 01:18:14 +00:00
|
|
|
</refentry>
|
2002-09-28 20:56:46 +00:00
|
|
|
<!-- 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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2002-09-28 20:56:46 +00:00
|
|
|
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
|
|
|
|
-->
|