Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Add roundFormat function (#3)
Browse files Browse the repository at this point in the history
* Add roundFormat function

* Apply fixes from StyleCI
  • Loading branch information
nicja authored Apr 21, 2017
1 parent 9c1f2f6 commit 7f0a99e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/MoneyTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ public function testToString()

/**
* @dataProvider testRoundProvider
*
* @param mixed $value
* @param mixed $precision
* @param mixed $mode
Expand Down

0 comments on commit 7f0a99e

Please sign in to comment.