Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE: See my improved answer here: <a href="https://stackoverflow.com/questions/1642614/how-to-ceil-floor-and-round-bcmath-numbers/1653826#1653826">How to ceil, floor and round bcmath numbers?</a>.</strong></p> <hr> <p>These functions seem to make more sense, at least to me:</p> <pre><code>function bcceil($number) { if ($number[0] != '-') { return bcadd($number, 1, 0); } return bcsub($number, 0, 0); } function bcfloor($number) { if ($number[0] != '-') { return bcadd($number, 0, 0); } return bcsub($number, 1, 0); } function bcround($number, $precision = 0) { if ($number[0] != '-') { return bcadd($number, '0.' . str_repeat('0', $precision) . '5', $precision); } return bcsub($number, '0.' . str_repeat('0', $precision) . '5', $precision); } </code></pre> <p><strong>They support negative numbers and the precision argument for the bcround() function.</strong></p> <p>Some tests:</p> <pre><code>assert(bcceil('4.3') == ceil('4.3')); // true assert(bcceil('9.999') == ceil('9.999')); // true assert(bcceil('-3.14') == ceil('-3.14')); // true assert(bcfloor('4.3') == floor('4.3')); // true assert(bcfloor('9.999') == floor('9.999')); // true assert(bcfloor('-3.14') == floor('-3.14')); // true assert(bcround('3.4', 0) == number_format('3.4', 0)); // true assert(bcround('3.5', 0) == number_format('3.5', 0)); // true assert(bcround('3.6', 0) == number_format('3.6', 0)); // true assert(bcround('1.95583', 2) == number_format('1.95583', 2)); // true assert(bcround('5.045', 2) == number_format('5.045', 2)); // true assert(bcround('5.055', 2) == number_format('5.055', 2)); // true assert(bcround('9.999', 2) == number_format('9.999', 2)); // true </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload