Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the decimal multiplying factor #3

Merged
merged 5 commits into from
Jun 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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