Skip to content

TypeError: Decimal\Decimal::add() expected parameter 1 to be a string, integer, or decimal #57

Description

@thefantas

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
)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions