php-doc-en/reference/strings/functions/number-format.xml
Máté Kocsis 2a7c919451 Generate string methodsynopses based on stubs
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>

Cf. <https://github.com/php/doc-en/pull/265>.
2021-01-01 19:19:03 +01:00

174 lines
4.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.number-format" xmlns="http://docbook.org/ns/docbook" 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>num</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>decimals</parameter><initializer>0</initializer></methodparam>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>decimal_separator</parameter><initializer>"."</initializer></methodparam>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>thousands_separator</parameter><initializer>","</initializer></methodparam>
</methodsynopsis>
<para>
Formats a number with grouped thousands and optionally decimal digits.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>num</parameter></term>
<listitem>
<para>
The number being formatted.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>decimals</parameter></term>
<listitem>
<para>
Sets the number of decimal digits.
If <literal>0</literal>, the <parameter>decimal_separator</parameter> is
omitted from the return value.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>decimal_separator</parameter></term>
<listitem>
<para>
Sets the separator for the decimal point.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>thousands_separator</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>num</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>8.0.0</entry>
<entry>
Prior to this version, <function>number_format</function> accepted
one, two, or four parameters (but not three).
</entry>
</row>
<row>
<entry>7.2.0</entry>
<entry>
<function>number_format</function> was changed to not being able to return
<literal>-0</literal>, previously <literal>-0</literal> could be returned
for cases like where <parameter>num</parameter> would be <literal>-0.01</literal>.
</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. The following example demonstrates various ways to format a number:
</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
-->