mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
number_format is more like a string function...
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@97282 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
7217a0d33d
commit
e6cfcd286e
1 changed files with 108 additions and 0 deletions
108
reference/strings/functions/number-format.xml
Normal file
108
reference/strings/functions/number-format.xml
Normal file
|
@ -0,0 +1,108 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<!-- 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>
|
||||
<methodparam choice="opt"><type>string</type><parameter>dec_point</parameter></methodparam>
|
||||
<methodparam choice="opt"><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>
|
||||
<note>
|
||||
<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>
|
||||
</note>
|
||||
<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.56
|
||||
|
||||
// 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
|
||||
-->
|
Loading…
Reference in a new issue