Skip to content

Commit 3c5878f

Browse files
committed
ensured figures are always rounded to 2 d.p. before being JSON serialized
1 parent 99f5e73 commit 3c5878f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/AmortizedMonth.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class AmortizedMonth implements JsonSerializable
4444
public function __construct(DateTime $date, float $principalDue = 0.0, float $interestDue = 0.0)
4545
{
4646
$this->date = $date;
47-
$this->principalDue = $principalDue;
48-
$this->interestDue = $interestDue;
47+
$this->principalDue = round($principalDue, 2);
48+
$this->interestDue = round($interestDue, 2);
4949
}
5050

5151
public function getTotalAmountDue(): float
@@ -69,9 +69,9 @@ public function setOverpayments(array $overpayments): AmortizedMonth
6969
*/
7070
public function getTotalOverpayments(): float
7171
{
72-
return array_reduce($this->overpayments, function(float $carry, Overpayment $overpayment) {
72+
return round(array_reduce($this->overpayments, function(float $carry, Overpayment $overpayment) {
7373
return $carry + $overpayment->getAmount();
74-
}, 0.0);
74+
}, 0.0), 2);
7575
}
7676

7777
/**

0 commit comments

Comments
 (0)