mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Added description for mode constants and an example to clarify further on the behavior of the different modes. Fixes bug #63568.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@328606 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
edcfded6c0
commit
ef12785e5a
1 changed files with 74 additions and 5 deletions
|
@ -69,10 +69,47 @@
|
|||
<term><parameter>mode</parameter></term>
|
||||
<listitem>
|
||||
<para>
|
||||
One of <constant>PHP_ROUND_HALF_UP</constant>,
|
||||
<constant>PHP_ROUND_HALF_DOWN</constant>,
|
||||
<constant>PHP_ROUND_HALF_EVEN</constant>, or
|
||||
<constant>PHP_ROUND_HALF_ODD</constant>.
|
||||
Use one of the following constants to specify the mode in which rounding occurs.
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Constant</entry>
|
||||
<entry>&Description;</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry><constant>PHP_ROUND_HALF_UP</constant></entry>
|
||||
<entry>
|
||||
Round <parameter>val</parameter> up to <parameter>precision</parameter> decimal places
|
||||
away from zero, when it is half way there. Making 1.5 into 2 and -1.5 into -2.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><constant>PHP_ROUND_HALF_DOWN</constant></entry>
|
||||
<entry>
|
||||
Round <parameter>val</parameter> down to <parameter>precision</parameter> decimal places
|
||||
towards zero, when it is half way there. Making 1.5 into 2 and -1.5 into -2.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><constant>PHP_ROUND_HALF_EVEN</constant></entry>
|
||||
<entry>
|
||||
Round <parameter>val</parameter> to <parameter>precision</parameter> decimal places
|
||||
towards the next even value.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry><constant>PHP_ROUND_HALF_ODD</constant></entry>
|
||||
<entry>
|
||||
Round <parameter>val</parameter> to <parameter>precision</parameter> decimal places
|
||||
towards the next odd value.
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -122,6 +159,38 @@ echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8
|
|||
echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8
|
||||
echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<example>
|
||||
<title><parameter>mode with precision</parameter> examples</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
/* Using PHP_ROUND_HALF_UP with 1 decimal digit precision */
|
||||
echo round( 1.55, 1, PHP_ROUND_HALF_UP); // 1.6
|
||||
echo round( 1.54, 1, PHP_ROUND_HALF_UP); // 1.5
|
||||
echo round(-1.55, 1, PHP_ROUND_HALF_UP); // -1.6
|
||||
echo round(-1.54, 1, PHP_ROUND_HALF_UP); // -1.5
|
||||
|
||||
/* Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision */
|
||||
echo round( 1.55, 1, PHP_ROUND_HALF_DOWN); // 1.5
|
||||
echo round( 1.54, 1, PHP_ROUND_HALF_DOWN); // 1.5
|
||||
echo round(-1.55, 1, PHP_ROUND_HALF_DOWN); // -1.5
|
||||
echo round(-1.54, 1, PHP_ROUND_HALF_DOWN); // -1.5
|
||||
|
||||
/* Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision */
|
||||
echo round( 1.55, 1, PHP_ROUND_HALF_EVEN); // 1.6
|
||||
echo round( 1.54, 1, PHP_ROUND_HALF_EVEN); // 1.5
|
||||
echo round(-1.55, 1, PHP_ROUND_HALF_EVEN); // -1.6
|
||||
echo round(-1.54, 1, PHP_ROUND_HALF_EVEN); // -1.5
|
||||
|
||||
/* Using PHP_ROUND_HALF_ODD with 1 decimal digit precision */
|
||||
echo round( 1.55, 1, PHP_ROUND_HALF_ODD); // 1.5
|
||||
echo round( 1.54, 1, PHP_ROUND_HALF_ODD); // 1.5
|
||||
echo round(-1.55, 1, PHP_ROUND_HALF_ODD); // -1.5
|
||||
echo round(-1.54, 1, PHP_ROUND_HALF_ODD); // -1.5
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -189,4 +258,4 @@ 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