mirror of
https://github.com/php/doc-es.git
synced 2026-04-24 07:38:19 +02:00
9f7804a633
* feat(translation): update revision EN * feat(translation): update revision EN
213 lines
5.9 KiB
XML
213 lines
5.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
||
<!-- EN-Revision: 45042fef652f1b4e904e809fcbfcf31f6c60670b Maintainer: PhilDaiguille Status: ready -->
|
||
<!-- Reviewed: yes -->
|
||
<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>Formatea un número para su visualización</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>
|
||
Formatea un número con los miles agrupados y opcionalmente con cifras decimales utilizando la regla de redondeo al más cercano.
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="parameters">
|
||
&reftitle.parameters;
|
||
<para>
|
||
<variablelist>
|
||
<varlistentry>
|
||
<term><parameter>num</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
El número a formatear.
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
<varlistentry>
|
||
<term><parameter>decimals</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
Define el número de cifras decimales.
|
||
Si es <literal>0</literal>, el <parameter>decimal_separator</parameter> es
|
||
omitido del valor de retorno.
|
||
A partir de PHP 8.3.0, cuando el valor es negativo, <parameter>num</parameter>
|
||
es redondeado a <parameter>decimals</parameter> cifras significativas antes
|
||
del punto decimal.
|
||
Antes de PHP 8.3.0, los valores negativos eran ignorados y tratados de la
|
||
misma manera que <literal>0</literal>.
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
<varlistentry>
|
||
<term><parameter>decimal_separator</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
Define el separador para el punto decimal.
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
<varlistentry>
|
||
<term><parameter>thousands_separator</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
Define el separador de miles.
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
</variablelist>
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="returnvalues">
|
||
&reftitle.returnvalues;
|
||
<para>
|
||
Una versión formateada del número <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>
|
||
Se añadió el manejo de valores negativos para <parameter>decimals</parameter>.
|
||
</entry>
|
||
</row>
|
||
<row>
|
||
<entry>8.0.0</entry>
|
||
<entry>
|
||
Antes de esta versión, <function>number_format</function> aceptaba
|
||
uno, dos o cuatro argumentos (pero no tres).
|
||
</entry>
|
||
</row>
|
||
<row>
|
||
<entry>7.2.0</entry>
|
||
<entry>
|
||
<function>number_format</function> fue modificado para no permitir devolver <literal>-0</literal>, anteriormente <literal>-0</literal> podía
|
||
ser devuelto para casos donde <parameter>num</parameter> valía <literal>-0.01</literal>.
|
||
</entry>
|
||
</row>
|
||
</tbody>
|
||
</tgroup>
|
||
</informaltable>
|
||
</para>
|
||
<example>
|
||
<title>Un valor negativo para <parameter>decimals</parameter></title>
|
||
<simpara>
|
||
A partir de PHP 8.3.0, un valor negativo para <parameter>decimals</parameter>
|
||
es utilizado para redondear el número de cifras significativas antes del punto
|
||
decimal.
|
||
</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="examples">
|
||
&reftitle.examples;
|
||
<para>
|
||
<example>
|
||
<title>Ejemplo con <function>number_format</function></title>
|
||
<para>
|
||
En notación francesa, se utilizan generalmente dos cifras
|
||
después de la coma, una coma como separador decimal y un
|
||
espacio como separador de miles. El siguiente ejemplo muestra
|
||
cómo formatear un número de diferentes maneras:
|
||
</para>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
|
||
$number = 1234.56;
|
||
|
||
// Notación inglesa (por omisión)
|
||
echo number_format($number), PHP_EOL;
|
||
// 1,235
|
||
|
||
// Notación francesa
|
||
echo number_format($number, 2, ',', ' '), PHP_EOL;
|
||
// 1 234,56
|
||
|
||
$number = 1234.5678;
|
||
|
||
// Notación inglesa sin separador de miles
|
||
echo number_format($number, 2, '.', ''), PHP_EOL;
|
||
// 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
|
||
-->
|