svn: /phpdoc/en/trunk/reference/math/functions/ round.xml

From: Date: Sun, 02 Dec 2012 07:17:13 +0000
Subject: svn: /phpdoc/en/trunk/reference/math/functions/ round.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-10820@lists.php.net to get a copy of this message
googleguy Sun, 02 Dec 2012 07:17:13 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=328606 Log: Added description for mode constants and an example to clarify further on the behavior of the different modes. Fixes bug #63568. Bug: https://bugs.php.net/63568 (Open) round() $mode parameter not explained Changed paths: U phpdoc/en/trunk/reference/math/functions/round.xml Modified: phpdoc/en/trunk/reference/math/functions/round.xml =================================================================== --- phpdoc/en/trunk/reference/math/functions/round.xml 2012-12-02 05:49:27 UTC (rev 328605) +++ phpdoc/en/trunk/reference/math/functions/round.xml 2012-12-02 07:17:13 UTC (rev 328606) @@ -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> @@ -125,6 +162,38 @@ ]]> </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> </para> </refsect1> <refsect1 role="changelog"> @@ -189,4 +258,4 @@ vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 ---> +--> \ No newline at end of file

« previous php.doc.cvs (#10820) next »