/** * @param Number|string $value * @return Currency */ public function setValue($value) { parent::setValue($value); if (preg_match('/^\\(.*\\)$/is', trim($value))) { $this->setNegative(true); $this->setRawValue('-' . $this->getValue()); } return $this; }
/** * @param $value * @return void */ public function setValue($value) { parent::setValue($value); if (!$this->limitUp() instanceof Infinity && $this->getRealValue() > $this->limitUp()->getValue()) { $this->setDiff(bcsub($this->getRealValue(), $this->limitUp()->getValue(), $this->getPrecision())); } elseif (!$this->limitDown() instanceof Infinity && $this->getRealValue() < $this->limitDown()->getValue()) { $this->setDiff(bcsub($this->limitDown()->getValue(), $this->getRealValue(), $this->getPrecision()) * -1); } else { $this->setDiff(0); } }
public function testComparisons() { $num = new Number(5); $this->assertTrue($num->isPositive()); $this->assertFalse($num->isNegative()); $this->assertFalse($num->isZero()); $this->assertTrue($num->isGreater(4)); $this->assertFalse($num->isLess(4)); $this->assertTrue($num->isEqual(5)); $num->setValue(0); $this->assertTrue($num->isZero()); $this->assertFalse($num->isPositive()); $this->assertFalse($num->isNegative()); }