mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-22 03:48:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@131848 c90b9560-bf6c-de11-be94-00142212c4b1
111 lines
3.7 KiB
XML
111 lines
3.7 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.5 $ -->
|
|
<!-- splitted from ./en/functions/math.xml, last change in rev 1.2 -->
|
|
<refentry id="function.number-format">
|
|
<refnamediv>
|
|
<refname>number_format</refname>
|
|
<refpurpose>Format a number with grouped thousands</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<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></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></methodparam>
|
|
<methodparam><type>string</type><parameter>dec_point</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>thousands_sep</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>number_format</function> returns a formatted version of
|
|
<parameter>number</parameter>. 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>
|
|
<para>
|
|
Only the first character of <parameter>thousands_sep</parameter>
|
|
is used. For example, if you use <literal>foo</literal> as
|
|
<parameter>thousands_sep</parameter> on the number
|
|
<literal>1000</literal>, <function>number_format</function> will
|
|
return <literal>1f000</literal>.
|
|
</para>
|
|
<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,234
|
|
|
|
// French notation
|
|
$nombre_format_francais = number_format($number, 2, ',', ' ');
|
|
// 1 234,56
|
|
|
|
$number = 1234.5678;
|
|
|
|
// english notation without thousands seperator
|
|
$english_format_number = number_format($number, 2, '.', '');
|
|
// 1234.57
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
See also: <function>sprintf</function>,
|
|
<function>printf</function> and <function>sscanf</function>.
|
|
</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:"../../../../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
|
|
-->
|