|
11 | 11 | <type>float</type><methodname>round</methodname>
|
12 | 12 | <methodparam><type class="union"><type>int</type><type>float</type></type><parameter>num</parameter></methodparam>
|
13 | 13 | <methodparam choice="opt"><type>int</type><parameter>precision</parameter><initializer>0</initializer></methodparam>
|
14 |
| - <methodparam choice="opt"><type>int</type><parameter>mode</parameter><initializer><constant>PHP_ROUND_HALF_UP</constant></initializer></methodparam> |
| 14 | + <methodparam choice="opt"><type class="union"><type>int</type><type>RoundingMode</type></type><parameter>mode</parameter><initializer>RoundingMode::HalfAwayFromZero</initializer></methodparam> |
15 | 15 | </methodsynopsis>
|
16 | 16 | <para>
|
17 | 17 | Returns the rounded value of <parameter>num</parameter> to
|
|
71 | 71 | <term><parameter>mode</parameter></term>
|
72 | 72 | <listitem>
|
73 | 73 | <para>
|
74 |
| - Use one of the following constants to specify the mode in which rounding occurs. |
| 74 | + Use <enumname>RoundingMode</enumname> or one of the following constants to specify the mode in which rounding occurs. |
75 | 75 | <informaltable>
|
76 | 76 | <tgroup cols="2">
|
77 | 77 | <thead>
|
|
112 | 112 | </tbody>
|
113 | 113 | </tgroup>
|
114 | 114 | </informaltable>
|
| 115 | + However, please note that some newly added modes only exist in <link linkend="enum.roundingmode">RoundingMode</link>. |
115 | 116 | </para>
|
116 | 117 | </listitem>
|
117 | 118 | </varlistentry>
|
|
145 | 146 | </row>
|
146 | 147 | </thead>
|
147 | 148 | <tbody>
|
| 149 | + <row> |
| 150 | + <entry>8.4.0</entry> |
| 151 | + <entry> |
| 152 | + Four new rounding modes have been added. |
| 153 | + </entry> |
| 154 | + </row> |
148 | 155 | <row>
|
149 | 156 | <entry>8.4.0</entry>
|
150 | 157 | <entry>
|
@@ -321,6 +328,61 @@ float(-1.5)
|
321 | 328 | ]]>
|
322 | 329 | </screen>
|
323 | 330 | </example>
|
| 331 | + <example> |
| 332 | + <title>Example of using <enumname>RoundingMode</enumname></title> |
| 333 | + <programlisting role="php"> |
| 334 | +<![CDATA[ |
| 335 | +<?php |
| 336 | +foreach (RoundingMode::cases() as $mode) { |
| 337 | + foreach ([ |
| 338 | + 8.5, |
| 339 | + 9.5, |
| 340 | + -3.5, |
| 341 | + ] as $number) { |
| 342 | + printf("%-17s: %+.17g -> %+.17g\n", $mode->name, $number, round($number, 0, $mode)); |
| 343 | + } |
| 344 | + echo "\n"; |
| 345 | +} |
| 346 | +?> |
| 347 | +]]> |
| 348 | + </programlisting> |
| 349 | + &example.outputs; |
| 350 | + <screen role="php"> |
| 351 | +<![CDATA[ |
| 352 | +HalfAwayFromZero : +8.5 -> +9 |
| 353 | +HalfAwayFromZero : +9.5 -> +10 |
| 354 | +HalfAwayFromZero : -3.5 -> -4 |
| 355 | +
|
| 356 | +HalfTowardsZero : +8.5 -> +8 |
| 357 | +HalfTowardsZero : +9.5 -> +9 |
| 358 | +HalfTowardsZero : -3.5 -> -3 |
| 359 | +
|
| 360 | +HalfEven : +8.5 -> +8 |
| 361 | +HalfEven : +9.5 -> +10 |
| 362 | +HalfEven : -3.5 -> -4 |
| 363 | +
|
| 364 | +HalfOdd : +8.5 -> +9 |
| 365 | +HalfOdd : +9.5 -> +9 |
| 366 | +HalfOdd : -3.5 -> -3 |
| 367 | +
|
| 368 | +TowardsZero : +8.5 -> +8 |
| 369 | +TowardsZero : +9.5 -> +9 |
| 370 | +TowardsZero : -3.5 -> -3 |
| 371 | +
|
| 372 | +AwayFromZero : +8.5 -> +9 |
| 373 | +AwayFromZero : +9.5 -> +10 |
| 374 | +AwayFromZero : -3.5 -> -4 |
| 375 | +
|
| 376 | +NegativeInfinity : +8.5 -> +8 |
| 377 | +NegativeInfinity : +9.5 -> +9 |
| 378 | +NegativeInfinity : -3.5 -> -4 |
| 379 | +
|
| 380 | +PositiveInfinity : +8.5 -> +9 |
| 381 | +PositiveInfinity : +9.5 -> +10 |
| 382 | +PositiveInfinity : -3.5 -> -3 |
| 383 | +]]> |
| 384 | + </screen> |
| 385 | + </example> |
324 | 386 | </para>
|
325 | 387 | </refsect1>
|
326 | 388 |
|
|
0 commit comments