note 109658 deleted from function.bcmod by aharvey
| From: | aharvey@php.net | Date: | Tue, 07 Aug 2012 01:47:15 +0000 |
| Subject: | note 109658 deleted from function.bcmod by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189936@lists.php.net to get a copy of this message | ||
Note Submitter: jl dot izquierdoch at gmail dot com
----
If you don't have bcmath installed and you need to use it. You may need these functions:
<?php
if(!function_exists('bcmul')){
function bcmul($left_operand, $right_operand, $scale = 0)
{
return round($left_operand * $right_operand, $scale);
}
}
if(!function_exists('bcdiv')){
function bcdiv($left_operand, $right_operand, $scale = 0)
{
return number_format($left_operand / $right_operand, $scale);
}
}
if(!function_exists('bcmod')){
function bcmod($left_operand, $modulus)
{
return $left_operand - ($modulus * floor($left_operand / $modulus));
}
}
if(!function_exists('bcadd')){
function bcadd($left_operand, $right_operand, $scale = 0)
{
return round($left_operand + $right_operand, $scale);
}
}
/* TEST */
echo '<pre>';
echo bcadd('1.234', '5'); // 6
echo "\r\n";
echo bcadd('1.234', '5', 4); // 6.2340
echo "\r\n";
echo bcmod('4', '2'); // 0
echo "\r\n";
echo bcmod('2', '4'); // 2
echo "\r\n";
echo bcdiv('105', '6.55957', 3); // 16.007
echo "\r\n";
echo bcmul('1.34747474747', '35', 3); // 47.161
echo "\r\n";
echo bcmul('2', '4'); // 8
echo '</pre>';
?>