<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.bcmath-number.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'bcmath-number.round.php',
    1 => 'BcMath\\Number::round',
    2 => 'Rounds an arbitrary precision number',
  ),
  'up' => 
  array (
    0 => 'class.bcmath-number.php',
    1 => 'BcMath\\Number',
  ),
  'prev' => 
  array (
    0 => 'bcmath-number.powmod.php',
    1 => 'BcMath\\Number::powmod',
  ),
  'next' => 
  array (
    0 => 'bcmath-number.serialize.php',
    1 => 'BcMath\\Number::__serialize',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/bc/bcmath/number/round.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="bcmath-number.round" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">BcMath\Number::round</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.4.0)</p><p class="refpurpose"><span class="refname">BcMath\Number::round</span> &mdash; <span class="dc-title">Rounds an arbitrary precision number</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-bcmath-number.round-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>BcMath\Number::round</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$precision</code><span class="initializer"> = 0</span></span>, <span class="methodparam"><span class="type"><a href="enum.roundingmode.php" class="type RoundingMode">RoundingMode</a></span> <code class="parameter">$mode</code><span class="initializer"> = <strong><code>RoundingMode::HalfAwayFromZero</code></strong></span></span>): <span class="type"><a href="class.bcmath-number.php" class="type BcMath\Number">BcMath\Number</a></span></div>

  <p class="simpara">
   Returns the rounded value of <var class="varname">$this</var> to
   specified <code class="parameter">precision</code>
   (number of digits after the decimal point).
   <code class="parameter">precision</code> can also be negative or zero (default).
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-bcmath-number.round-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <dl>
   
   
     <dt><code class="parameter">precision</code></dt>
     <dd>
      <p class="para">
       Auf wie viele Nachkommastellen gerundet werden soll.
      </p>
      <p class="para">
       Ist die Genauigkeit <code class="parameter">precision</code> positiv, wird
       <code class="parameter">num</code> auf <code class="parameter">precision</code>
       signifikante Stellen nach dem Dezimalpunkt gerundet.
      </p>
      <p class="para">
       Ist die Genauigkeit <code class="parameter">precision</code> negativ, wird
       <code class="parameter">num</code> auf <code class="parameter">precision</code>
       signifikante Stellen vor dem Dezimalpunkt gerundet, d. h. auf das
       nächste Vielfache von <code class="literal">pow(10, -precision)</code>, z. B.
       wird <code class="parameter">num</code> mit einer
       <code class="parameter">precision</code> von -1 auf Zehner gerundet, mit einer
       <code class="parameter">precision</code> von -2 auf Hunderter usw.
      </p>
     </dd>
    
   
    <dt><code class="parameter">mode</code></dt>
    <dd>
     <span class="simpara">
      Specifies the rounding mode. For more information about modes, see <span class="enumname"><a href="enum.roundingmode.php" class="enumname">RoundingMode</a></span>.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-bcmath-number.round-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="simpara">
   Returns the result as a new <span class="classname"><a href="class.bcmath-number.php" class="classname">BcMath\Number</a></span> object.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-bcmath-number.round-errors">
  <h3 class="title">Fehler/Exceptions</h3>
  <p class="simpara">
   This method throws a <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> if an invalid <code class="parameter">mode</code> is specified.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-bcmath-number.round-examples">
  <h3 class="title">Beispiele</h3>
   <div class="example" id="example-1">
   <p><strong>Beispiel #1 <span class="methodname"><strong>BcMath\Number::round()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />var_dump</span><span style="color: #007700">(<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'3.4'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(),<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'3.5'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(),<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'3.6'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(),<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'3.6'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">),<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'5.045'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">),<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'5.055'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">),<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'345'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(-</span><span style="color: #0000BB">2</span><span style="color: #007700">),<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'345'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(-</span><span style="color: #0000BB">3</span><span style="color: #007700">),<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'678'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(-</span><span style="color: #0000BB">2</span><span style="color: #007700">),<br />    new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'678'</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(-</span><span style="color: #0000BB">3</span><span style="color: #007700">),<br />);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">object(BcMath\Number)#2 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;3&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;4&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;4&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#5 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;4&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#6 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;5.05&quot;
  [&quot;scale&quot;]=&gt;
  int(2)
}
object(BcMath\Number)#7 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;5.06&quot;
  [&quot;scale&quot;]=&gt;
  int(2)
}
object(BcMath\Number)#8 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;300&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#9 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;0&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#10 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;700&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#11 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;1000&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
   <p><strong>Beispiel #2 
    Example of using <span class="methodname"><strong>BcMath\Number::round()</strong></span> with different <code class="parameter">precision</code> values
   </strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$number </span><span style="color: #007700">= new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'123.45'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">3</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">2</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(-</span><span style="color: #0000BB">1</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(-</span><span style="color: #0000BB">2</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(-</span><span style="color: #0000BB">3</span><span style="color: #007700">),<br />);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">object(BcMath\Number)#2 (2) {
  [&quot;value&quot;]=&gt;
  string(7) &quot;123.450&quot;
  [&quot;scale&quot;]=&gt;
  int(3)
}
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(6) &quot;123.45&quot;
  [&quot;scale&quot;]=&gt;
  int(2)
}
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(5) &quot;123.5&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#5 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;123&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#6 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;120&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#7 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;100&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#8 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;0&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-3">
   <p><strong>Beispiel #3 
    Example of using <span class="methodname"><strong>BcMath\Number::round()</strong></span> with different <code class="parameter">mode</code> values
   </strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">'Rounding modes with 9.5' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$number </span><span style="color: #007700">= new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'9.5'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfAwayFromZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfTowardsZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfEven</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfOdd</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">TowardsZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">AwayFromZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">NegativeInfinity</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">PositiveInfinity</span><span style="color: #007700">),<br />);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'Rounding modes with 8.5' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$number </span><span style="color: #007700">= new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'8.5'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfAwayFromZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfTowardsZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfEven</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfOdd</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">TowardsZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">AwayFromZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">NegativeInfinity</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$number</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">PositiveInfinity</span><span style="color: #007700">),<br />);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Rounding modes with 9.5
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(2) &quot;10&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#5 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;9&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#7 (2) {
  [&quot;value&quot;]=&gt;
  string(2) &quot;10&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#9 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;9&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#11 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;9&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#13 (2) {
  [&quot;value&quot;]=&gt;
  string(2) &quot;10&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#15 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;9&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#17 (2) {
  [&quot;value&quot;]=&gt;
  string(2) &quot;10&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}

Rounding modes with 8.5
object(BcMath\Number)#1 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;9&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#15 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;8&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#13 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;8&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#11 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;9&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#9 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;8&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#7 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;9&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#5 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;8&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}
object(BcMath\Number)#3 (2) {
  [&quot;value&quot;]=&gt;
  string(1) &quot;9&quot;
  [&quot;scale&quot;]=&gt;
  int(0)
}</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-4">
   <p><strong>Beispiel #4 
    Example of using <span class="methodname"><strong>BcMath\Number::round()</strong></span> with different <code class="parameter">mode</code> values
    when specifying <code class="parameter">precision</code>
   </strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$positive </span><span style="color: #007700">= new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'1.55'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$negative </span><span style="color: #007700">= new </span><span style="color: #0000BB">BcMath\Number</span><span style="color: #007700">(</span><span style="color: #DD0000">'-1.55'</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">'Using RoundingMode::HalfAwayFromZero with 1 decimal digit precision' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$positive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfAwayFromZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$negative</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfAwayFromZero</span><span style="color: #007700">),<br />);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'Using RoundingMode::HalfTowardsZero with 1 decimal digit precision' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$positive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfTowardsZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$negative</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfTowardsZero</span><span style="color: #007700">),<br />);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'Using RoundingMode::HalfEven with 1 decimal digit precision' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$positive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfEven</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$negative</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfEven</span><span style="color: #007700">),<br />);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'Using RoundingMode::HalfOdd with 1 decimal digit precision' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$positive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfOdd</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$negative</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">HalfOdd</span><span style="color: #007700">),<br />);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'Using RoundingMode::TowardsZero with 1 decimal digit precision' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$positive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">TowardsZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$negative</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">TowardsZero</span><span style="color: #007700">),<br />);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'Using RoundingMode::AwayFromZero with 1 decimal digit precision' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$positive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">AwayFromZero</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$negative</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">AwayFromZero</span><span style="color: #007700">),<br />);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'Using RoundingMode::NegativeInfinity with 1 decimal digit precision' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$positive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">NegativeInfinity</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$negative</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">NegativeInfinity</span><span style="color: #007700">),<br />);<br /><br />echo </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'Using RoundingMode::PositiveInfinity with 1 decimal digit precision' </span><span style="color: #007700">. </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">$positive</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">PositiveInfinity</span><span style="color: #007700">),<br />    </span><span style="color: #0000BB">$negative</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">round</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">RoundingMode</span><span style="color: #007700">::</span><span style="color: #0000BB">PositiveInfinity</span><span style="color: #007700">),<br />);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt folgende Ausgabe:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Using RoundingMode::HalfAwayFromZero with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.6&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#5 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;-1.6&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}

Using RoundingMode::HalfTowardsZero with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.5&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#6 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;-1.5&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}

Using RoundingMode::HalfEven with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.6&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#7 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;-1.6&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}

Using RoundingMode::HalfOdd with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.5&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#8 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;-1.5&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}

Using RoundingMode::TowardsZero with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.5&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#9 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;-1.5&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}

Using RoundingMode::AwayFromZero with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.6&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#10 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;-1.6&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}

Using RoundingMode::NegativeInfinity with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.5&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#11 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;-1.6&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}

Using RoundingMode::PositiveInfinity with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
  [&quot;value&quot;]=&gt;
  string(3) &quot;1.6&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}
object(BcMath\Number)#12 (2) {
  [&quot;value&quot;]=&gt;
  string(4) &quot;-1.5&quot;
  [&quot;scale&quot;]=&gt;
  int(1)
}</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-bcmath-number.round-seealso">
  <h3 class="title">Siehe auch</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.bcround.php" class="function" rel="rdfs-seeAlso">bcround()</a> - Round arbitrary precision number</span></li>
   <li><span class="methodname"><a href="bcmath-number.ceil.php" class="methodname" rel="rdfs-seeAlso">BcMath\Number::ceil()</a> - Rounds up an arbitrary precision number</span></li>
   <li><span class="methodname"><a href="bcmath-number.floor.php" class="methodname" rel="rdfs-seeAlso">BcMath\Number::floor()</a> - Rounds down an arbitrary precision number</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>