Skip to content

Commit

Permalink
Merge 4aa4d97 into fd5985f
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirRebilly committed Mar 4, 2019
2 parents fd5985f + 4aa4d97 commit d0222d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Security - in case of vulnerabilities.

_TBD_

## 1.0.1 (2019-03-05)

### Fixed
+ Fixed pretty-print formatting of negative amount of money

## 1.0.0 (2018-12-08)

Initial Release
6 changes: 5 additions & 1 deletion src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ public function getFormattedAmount(string $decimalPoint = '.', string $thousands
*/
public function getPrettyPrint(string $decimalPoint = '.', string $thousandsSeparator = ','): string
{
return $this->getCurrency()->getSign() . $this->getFormattedAmount($decimalPoint, $thousandsSeparator);
$currencySign = $this->getCurrency()->getSign();
$formattedAmount = ltrim($this->getFormattedAmount($decimalPoint, $thousandsSeparator), '-');
$amountSign = $this->isNegative() ? '-':'';

return "{$amountSign}{$currencySign}{$formattedAmount}";
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ public function testFormattedAmountCanBeRetrieved(): void
$this->assertSame('€1,200.34', $m->getPrettyPrint('.', ','));
}

public function testFormattedNegativeAmountCanBeRetrieved(): void
{
$m = new Money(-120034, new Currency('EUR'));
$this->assertSame('-1 200.34', $m->getFormattedAmount('.', ' '));
$this->assertSame('-€1,200.34', $m->getPrettyPrint('.', ','));
}

/**
* @depends testObjectCanBeConstructedFromIntegerValueAndCurrencyObject
*
Expand Down

0 comments on commit d0222d6

Please sign in to comment.