Why Decimal does not accept float? It is a nuisance to make use of strval() or (string) in addition to checking that it is not NULL or empty.
use Decimal\Decimal;
class ModDecimal {
public $decimal;
function __construct($val = '') {
$var = strval(empty(trim($val))?'0':trim($val));
$this->decimal = new Decimal($var);
}
function get_decimal() {
return $this->decimal;
}
}
$ok = (new ModDecimal(" 5.05"))->get_decimal()->add(20);
print_r($ok);
Decimal\Decimal Object
(
[value] => 25.05
[precision] => 28
)
Why Decimal does not accept float? It is a nuisance to make use of strval() or (string) in addition to checking that it is not NULL or empty.