/** * Subtracts the passed monetary value from the current one * * @throws fValidationException When `$subtrahend` is not a valid number/monetary value * * @param fMoney|string|integer $subtrahend The money object to subtract - a string or integer will be converted to the default currency (if defined) * @return fMoney The difference of the monetary values in this currency */ public function sub($subtrahend) { $subtrahend = $this->makeMoney($subtrahend); $converted_subtrahend = $subtrahend->convert($this->currency)->amount; $precision = self::getCurrencyInfo($this->currency, 'precision'); $new_amount = $this->amount->sub($converted_subtrahend, $precision + 1)->round($precision); return new fMoney($new_amount, $this->currency); }
/** * @dataProvider invalidNumProvider * @expectedException fValidationException */ public function testSubFail($number) { $num = new fNumber('1'); $num->sub($number); }