From 7f0a99e63baf782eb9dcf82029b7bddb235364f3 Mon Sep 17 00:00:00 2001 From: Nic Date: Fri, 21 Apr 2017 16:28:20 +0200 Subject: [PATCH] Add roundFormat function (#3) * Add roundFormat function * Apply fixes from StyleCI --- changelog.md | 5 +++++ src/Money.php | 13 +++++++++++++ tests/MoneyTests.php | 1 + 3 files changed, 19 insertions(+) diff --git a/changelog.md b/changelog.md index 3bce00b..9469a1d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## 1.0.5 - 2017-04-21 + +* Add `roundFormat()` function which first rounds, then formats the amount, as the regular `format()` function +truncates any additional data, resulting in a loss of accuracy + ## 1.0.4 - 2016-02-01 * Fix typod class name PHPDocBlockTest diff --git a/src/Money.php b/src/Money.php index 09b2f0e..83bb9bf 100644 --- a/src/Money.php +++ b/src/Money.php @@ -280,6 +280,19 @@ public function toCurrency(Currency $currency) return new self($new, $currency); } + /** + * @param int $precision + * @param string $decPoint + * @param string $thousandsSep + * @param int $mode + * + * @return string + */ + public function roundFormat($precision = 2, $decPoint = '.', $thousandsSep = '', $mode = PHP_ROUND_HALF_EVEN) + { + return $this->round($precision, $mode)->format($precision, $decPoint, $thousandsSep); + } + /** * @param int $precision * @param string $decPoint diff --git a/tests/MoneyTests.php b/tests/MoneyTests.php index a01a0e8..6587af1 100644 --- a/tests/MoneyTests.php +++ b/tests/MoneyTests.php @@ -681,6 +681,7 @@ public function testToString() /** * @dataProvider testRoundProvider + * * @param mixed $value * @param mixed $precision * @param mixed $mode