Skip to content

Commit 4474c2b

Browse files
authored
Merge pull request #6 from dalholm/master
Divide rate with 100
2 parents 8ca2124 + 356aad9 commit 4474c2b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Money.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function divideBy(float $number): self
115115
public function addFee(float $rate): self
116116
{
117117
return $this->multiplyBy(
118-
round(1 + $rate, $this->currency->mathDecimals())
118+
round(1 + ($rate / 100), $this->currency->mathDecimals())
119119
);
120120
}
121121

@@ -129,7 +129,7 @@ public function addTax(float $rate): self
129129
public function subtractFee(float $rate): self
130130
{
131131
return $this->divideBy(
132-
round(1 + $rate, $this->currency->mathDecimals())
132+
round(1 + ($rate / 100), $this->currency->mathDecimals())
133133
);
134134
}
135135

tests/Pest/MoneyTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,19 @@
104104
test('fees can be added to and subtracted from money', function () {
105105
$money = Money::fromDecimal(10.0);
106106

107-
expect($money->addFee(0.1)->decimal())->toBe(11.0);
108-
expect($money->subtractFee(0.1)->decimal())->toBe(9.09); // 10/1.1
107+
expect($money->addFee(10)->decimal())->toBe(11.0);
108+
expect($money->subtractFee(10)->decimal())->toBe(9.09); // 10/1.1
109109
});
110110

111111
test('taxes can be added and subtracted from money', function () {
112112
currencies()->add([CZK::class]);
113113

114114
expect(
115-
Money::fromDecimal(100.0, 'CZK')->addTax(0.21)->decimal()
115+
Money::fromDecimal(100.0, 'CZK')->addTax(21.0)->decimal()
116116
)->toBe(121.0);
117117

118118
expect(
119-
Money::fromDecimal(121.0, 'CZK')->subtractTax(0.21)->decimal()
119+
Money::fromDecimal(121.0, 'CZK')->subtractTax(21.0)->decimal()
120120
)->toBe(100.0);
121121
});
122122

0 commit comments

Comments
 (0)