money-math
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -102,2 +102,8 @@ (function (exports) { | ||
exports.subtract = function (a, b) { | ||
return exports.centsToAmount( | ||
bignum(exports.amountToCents(a)).sub(exports.amountToCents(b)).toString() | ||
); | ||
}; | ||
exports.mul = function (a, b) { | ||
@@ -104,0 +110,0 @@ return exports.centsToAmount( |
{ | ||
"name": "money-math", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "bignum-based arbitrary precision operations on currency amounts \"XXX.YY\"; because floats are BAD for representing money", | ||
@@ -25,2 +25,3 @@ "main": "money.js", | ||
"bigint", | ||
"bignum", | ||
"arithmetic", | ||
@@ -27,0 +28,0 @@ "arbitrary", |
@@ -0,5 +1,7 @@ | ||
[](http://travis-ci.org/ikr/money-math) | ||
# What does it do? | ||
Adds, multiplies the currency _amounts,_ and calculates percentages of _amounts._ The result of | ||
each of those operations is also an _amount_: a string, strictly matching the `/^\-?\d+\.\d\d$/` | ||
each of those operations is also an _amount:_ a string, strictly matching the `/^\-?\d+\.\d\d$/` | ||
pattern, like "0.25", "1000.00", or "-42.10". | ||
@@ -6,0 +8,0 @@ |
@@ -133,2 +133,14 @@ (function () { | ||
describe("money.subtract()", function () { | ||
it("calculates difference 1", function () { | ||
expect( | ||
money.subtract("700000000000000000000.00", "700000000000000000000.00") | ||
).toBe("0.00"); | ||
}); | ||
it("calculates difference 2", function () { | ||
expect(money.subtract("-10.00", "5.00")).toBe("-15.00"); | ||
}); | ||
}); | ||
describe("money.mul()", function () { | ||
@@ -135,0 +147,0 @@ it("multiplies two decimals 1", function () { |
14179
262
55