Example #1
0
 /**
  * @param $value
  * @param bool $strict
  * @param bool $paranoid
  * @return float|int
  * @throws \Granam\Float\Tools\Exceptions\WrongParameterType
  * @throws \Granam\Float\Tools\Exceptions\ValueLostOnCast
  */
 private static function convertToNumber($value, $strict, $paranoid)
 {
     try {
         return ToNumber::toNumber($value, $strict, $paranoid);
     } catch (\Granam\Number\Tools\Exceptions\WrongParameterType $exception) {
         throw new Exceptions\WrongParameterType($exception->getMessage(), $exception->getCode(), $exception);
     } catch (\Granam\Number\Tools\Exceptions\ValueLostOnCast $exception) {
         throw new Exceptions\ValueLostOnCast($exception->getMessage(), $exception->getCode(), $exception);
     }
 }
 /**
  * @param mixed $value
  * @param bool $strict = false Accepts only explicit values, no null or empty string
  * @param bool $paranoid = false Throws exception if some value is lost on cast because of rounding
  * @throws \Granam\Number\Tools\Exceptions\WrongParameterType
  * @throws \Granam\Number\Tools\Exceptions\NegativeNumberCanNotBePositive
  * @throws \Granam\Scalar\Tools\Exceptions\WrongParameterType
  */
 public function __construct($value, $strict = true, $paranoid = false)
 {
     parent::__construct(ToNumber::toNegativeNumber($value), $strict, $paranoid);
 }
 /**
  * @test
  * @expectedException \Granam\Number\Tools\Exceptions\PositiveNumberCanNotBeNegative
  */
 public function I_can_not_use_negative_number_as_positive()
 {
     ToNumber::toPositiveNumber(-0.001);
 }
 /**
  * @param int|float|NumberInterface $value
  * @return NumberInterface
  * @throws \Granam\Number\Tools\Exceptions\WrongParameterType
  * @throws \Granam\Scalar\Tools\Exceptions\WrongParameterType
  */
 public function sub($value)
 {
     return new static($this->getValue() - ToNumber::toNumber($value, $this->strict, $this->paranoid), $this->strict, $this->paranoid);
 }