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);
     }
 }
 /**
  * @test
  */
 public function I_can_convert_even_number_object_to_number()
 {
     self::assertSame(123, ToNumber::toNumber(new NumberObject(123)));
 }
 /**
  * @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);
 }