Skip to content

Commit

Permalink
Merge 4857fdc into 8e78ca3
Browse files Browse the repository at this point in the history
  • Loading branch information
vongohren committed Jun 15, 2015
2 parents 8e78ca3 + 4857fdc commit 8d75623
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Money(amount, currency) {
throw new Error("The currency " + currency.code + " supports only "
+ currency.decimal_digits + " decimal digits");

this.amount = decimals > 0 ? amount * multipliers[decimals] : amount;
this.amount = decimals > 0 ? amount * multipliers[currency.decimal_digits] : amount;
this.currency = currency.code;
Object.freeze(this);
}
Expand Down
7 changes: 7 additions & 0 deletions test/money.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ describe('Money', function () {
expect(money.currency).to.equal('EUR');
});

it('should create a new instance with correct decimals from object', function () {
var money = new Money({amount: 11.5, currency: 'EUR'});

expect(money.amount).to.equal(1150);
expect(money.currency).to.equal('EUR');
});

it('should create a new instance from object with currenct object', function () {
var money = new Money({amount: 11.51, currency: Money.EUR});

Expand Down

0 comments on commit 8d75623

Please sign in to comment.