Commit 9a104702 authored by Thorsten Buss's avatar Thorsten Buss

add ->abs() method to Money to get the absolute amount as MoneyObj (without leading sign)

parent ddcd72b6
......@@ -563,4 +563,12 @@ class Money implements \JsonSerializable, Jsonable, Arrayable {
protected function dbl($amount, $currency=null) {
return new static($amount, $currency ?: $this->currency());
}
/**
* return a new MoneyObj with the current amount without a leading sign
* @return $this
*/
public function abs() {
return $this->dbl(abs($this->amountToCalc()));
}
}
......@@ -381,4 +381,11 @@ class MoneyTest extends \PHPUnit_Framework_TestCase {
$this->money(0.00);
$this->assertTrue(true);
}
public function testAbs() {
$this->assertEquals($this->money(12300)->abs(), $this->money(12300));
$this->assertEquals($this->money(-12300)->abs(), $this->money(12300));
$this->assertEquals($this->money(12312)->abs(), $this->money(12312));
$this->assertEquals($this->money(-12312)->abs(), $this->money(12312));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment