mirror of
https://github.com/php/doc-pl.git
synced 2026-03-25 23:52:07 +01:00
213 lines
5.9 KiB
XML
213 lines
5.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 45042fef652f1b4e904e809fcbfcf31f6c60670b Maintainer: sobak Status: ready -->
|
|
<!-- $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>Formatuje liczbę grupując tysiące</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>
|
|
Tworzy liczbę z pogrupowanymi tysiącami i opcjonalnie cyframi dziesiętnymi przy użyciu zasady zaokrąglania o połowę w górę.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>num</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Liczba do sformatowania.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>decimals</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Ustawia liczbę cyfr po przecinku.
|
|
Jeśli <literal>0</literal>, <parameter>decimal_separator</parameter> jest
|
|
pomijany z wartości zwracanej.
|
|
Od PHP 8.3.0 kiedy wartość jest ujemna, <parameter>num</parameter>
|
|
jest zaokrąglane do ilości cyfr znaczących oznaczonych przez <parameter>decimals</parameter> przed
|
|
kropką dziesiętną.
|
|
Przed PHP 8.3.0 ujemne wartości były ignorowane i obsługiwane
|
|
tak samo jak <literal>0</literal>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>decimal_separator</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Ustawia separator dla miejsc dziesiętnych.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>thousands_separator</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Ustawia separator dla tysięcy.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Sformatowana <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.3.0</entry>
|
|
<entry>
|
|
Dodano obsługę ujemnych wartości dla parametru <parameter>decimals</parameter>.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
Przed tą wersją <function>number_format</function> akceptowała
|
|
jeden, dwa, lub cztery parametry (ale nie trzy).
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>7.2.0</entry>
|
|
<entry>
|
|
<function>number_format</function> zostałą zmieniona, aby nie mogła zwracać
|
|
<literal>-0</literal>, wcześniej <literal>-0</literal> mogło być zwrócone
|
|
dla przypadków, w których <parameter>num</parameter> byłoby równe<literal>-0.01</literal>.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Przykład użycia <function>number_format</function></title>
|
|
<para>
|
|
Przykładowo, notacja francuska zazwyczaj używa dwóch miejsc dziesiętnych,
|
|
przecinka (',') jako ich separatora i spacji (' ') jako
|
|
separatora tysięcy. Poniższy przykład demonstruje rózne sposoby formatowania liczb:
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$number = 1234.56;
|
|
|
|
// notacja angielska (domyślna)
|
|
echo number_format($number), PHP_EOL;
|
|
// 1,235
|
|
|
|
// notacja francuska
|
|
echo number_format($number, 2, ',', ' '), PHP_EOL;
|
|
// 1 234,56
|
|
|
|
$number = 1234.5678;
|
|
|
|
// notacja angielska bez separatora tysięcy
|
|
echo number_format($number, 2, '.', ''), PHP_EOL;
|
|
// 1234.57
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<example>
|
|
<title>Ujemna wartość dla parametru <parameter>decimals</parameter></title>
|
|
<simpara>
|
|
Od PHP 8.3.0 ujemna wartość dla <parameter>decimals</parameter>
|
|
jest używana do zaokrąglenia liczby cyfr znaczących przed kropką
|
|
dziesiętną.
|
|
</simpara>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$number = "1234.5678";
|
|
var_dump(number_format($number, -1));
|
|
var_dump(number_format($number, -2));
|
|
var_dump(number_format($number, -3));
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
string(5) "1,230"
|
|
string(5) "1,200"
|
|
string(5) "1,000"
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</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
|
|
-->
|