/** * Divides $this by $divisor and returns a new value object. * Uses the default rounding method (ROUND_HALF_EVEN) which is preferred for financial calculations. * @param Money|int|float|string $divisor * @return Money|string */ public function divide($divisor) { if ($divisor instanceof Money) { return $this->mathProvider->divide($this->getValue(), $divisor->getValue(), MathProvider::ROUND_MODE_NONE); } else { return new static($this->mathProvider->divide($this->getValue(), (string) $divisor), $this->mathProvider); } }
public function testComparisons() { $oneDollar1 = new Money('100', $this->mathProvider); $oneDollar2 = new Money('100', $this->mathProvider); $twoDollar1 = new Money('200', $this->mathProvider); $this->assertTrue($oneDollar1->equals($oneDollar2)); $this->assertFalse($oneDollar1->equals($twoDollar1)); $this->assertFalse($oneDollar1->greaterThan($oneDollar2)); $this->assertFalse($twoDollar1->lessThan($oneDollar1)); $this->assertFalse($oneDollar1->lessThan($oneDollar2)); $this->assertTrue($oneDollar1->lessThan($twoDollar1)); $this->assertTrue($twoDollar1->greaterThan($oneDollar1)); }