45 lines
959 B
PHP
45 lines
959 B
PHP
<?php
|
|
namespace App\Tools;
|
|
|
|
class Math
|
|
{
|
|
const SCALE = 8;
|
|
const SCALE_4 = 4;
|
|
const SCALE_6= 6;
|
|
const SCALE_8= 8;
|
|
const DECIMAL_6= 6;
|
|
static function bcMul($a1,$a2,$scale = self::SCALE): string
|
|
{
|
|
return bcmul($a1,$a2,$scale);
|
|
}
|
|
|
|
static function bcSub($a1,$a2,$scale = self::SCALE): string
|
|
{
|
|
return bcsub($a1,$a2,$scale);
|
|
}
|
|
|
|
static function bcAdd($a1,$a2,$scale = self::SCALE): string
|
|
{
|
|
return bcadd($a1,$a2,$scale);
|
|
}
|
|
|
|
static function bcComp($a1,$a2,$scale = self::SCALE): string
|
|
{
|
|
return bccomp($a1,$a2,$scale);
|
|
}
|
|
|
|
static function valueToAmount($amount,$decimal = self::DECIMAL_6,$scale = self::SCALE_8): string
|
|
{
|
|
return (float) bcdiv((string)$amount, '1e'.$decimal, $scale);
|
|
}
|
|
|
|
static function amountToValue($amount,$decimal = self::DECIMAL_6): string
|
|
{
|
|
return (float) bcmul((string)$amount, '1e'.$decimal,0);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|