From 8527d051b0a02bbf9d5f26f10299daf10d647019 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 14 Apr 2016 13:20:19 -0700 Subject: Fix eth resolution utils.formatBalance was returning rounded ether, was not useful for displaying account balances. Now returns four decimal points, and is easily configurable for more, with passing tests. Spoiler alert: Don't you dare divide bignumber wei. Bignumber does not have decimals. Keep it as wei, format it as ether. --- ui/test/unit/util_test.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'ui/test') diff --git a/ui/test/unit/util_test.js b/ui/test/unit/util_test.js index 52635eb89..7e34bba1c 100644 --- a/ui/test/unit/util_test.js +++ b/ui/test/unit/util_test.js @@ -63,9 +63,21 @@ describe('util', function() { }) it('should return eth as string followed by ETH', function() { - var input = new ethUtil.BN(ethInWei).toJSON() + var input = new ethUtil.BN(ethInWei, 10).toJSON() var result = util.formatBalance(input) - assert.equal(result, '1 ETH') + assert.equal(result, '1.0000 ETH') + }) + + it('should return eth as string followed by ETH', function() { + var input = new ethUtil.BN(ethInWei, 10).div(new ethUtil.BN('2', 10)).toJSON() + var result = util.formatBalance(input) + assert.equal(result, '.5000 ETH') + }) + + it('should display four decimal points', function() { + var input = "0x128dfa6a90b28000" + var result = util.formatBalance(input) + assert.equal(result, '1.3370 ETH') }) }) -- cgit v1.2.3