Skip to content

Commit

Permalink
fix: Change mod() logic so it actually works
Browse files Browse the repository at this point in the history
  • Loading branch information
kirb committed Feb 24, 2022
1 parent 68e633b commit 92d3de7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ export default class Money {
return this.performOperation("divide", ...amounts);
}

mod(...amounts: MoneyInput[]): Money {
return this.performOperation("modulus", ...amounts);
mod(amount: MoneyInput): Money {
let modulus = new Money(amount);
if (!this.amount.endsWith(".00") || !modulus.amount.endsWith(".00")) {
throw new TypeError("Modulus of non-integers not supported");
}
let value = this.value
.round(0, RoundingModes.HALF_EVEN)
.modulus(modulus.value.round(0, RoundingModes.HALF_EVEN));
return new Money(value, this.currency);
}

percent(amount: MoneyInput): Money {
Expand Down

0 comments on commit 92d3de7

Please sign in to comment.