diff options
| -rw-r--r-- | lib/finance.js | 3 | ||||
| -rw-r--r-- | test/finance.unit.js | 18 |
2 files changed, 16 insertions, 5 deletions
diff --git a/lib/finance.js b/lib/finance.js index c16b9e49..917719d5 100644 --- a/lib/finance.js +++ b/lib/finance.js @@ -110,8 +110,9 @@ var Finance = function (faker) { dec = dec === undefined ? 2 : dec; symbol = symbol || ''; var randValue = faker.random.number({ max: max, min: min, precision: Math.pow(10, -dec) }); + var stringNumber = symbol + randValue.toFixed(dec); - return symbol + randValue.toFixed(dec); + return Number(stringNumber); }; /** diff --git a/test/finance.unit.js b/test/finance.unit.js index 6c1cb142..432a9332 100644 --- a/test/finance.unit.js +++ b/test/finance.unit.js @@ -160,9 +160,9 @@ describe('finance.js', function () { }); - it("should use the defaul decimal location when not passing arguments", function () { + it("should use the default decimal location when not passing arguments", function () { - var amount = faker.finance.amount(); + var amount = faker.finance.amount().toString(); var decimal = '.'; var expected = amount.length - 3; @@ -200,7 +200,7 @@ describe('finance.js', function () { var amount = faker.finance.amount(100, 100, 1); assert.ok(amount); - assert.strictEqual(amount , '100.0', "the amount should be equal 100.0"); + assert.strictEqual(amount , 100.0, "the amount should be equal 100.0"); }); it("it should handle argument dec = 0", function () { @@ -208,7 +208,17 @@ describe('finance.js', function () { var amount = faker.finance.amount(100, 100, 0); assert.ok(amount); - assert.strictEqual(amount , '100', "the amount should be equal 100"); + assert.strictEqual(amount , 100, "the amount should be equal 100"); + }); + + it("it should return a number", function() { + + var amount = faker.finance.amount(100, 100, 0); + + var typeOfAmount = typeof amount; + + assert.ok(amount); + assert.strictEqual(typeOfAmount , 'number', "the amount type should be number"); }); }); |
