From cfe4b3ea2febc4510c6918ef9f4db4c11d5ef3a4 Mon Sep 17 00:00:00 2001 From: Gosuto Date: Sun, 28 Jan 2018 19:13:50 +0700 Subject: [PATCH] changed default decimals for money to 2 and for bitcoin to 8 (recommit) --- src/Format.js | 9 +++++---- test/model/testFormat.js | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Format.js b/src/Format.js index 7a1e788..e0b6705 100644 --- a/src/Format.js +++ b/src/Format.js @@ -6,9 +6,10 @@ export default class Format { return '' } let formatter = new Intl.NumberFormat('en-US', { - minimumFractionDigits: 0 + minimumFractionDigits: 2, + maximumFractionDigits: 2 }) - return formatter.format(parseInt(number)) + return formatter.format(parseFloat(number)) } static percent(number) { @@ -19,7 +20,7 @@ export default class Format { } static bitcoin(number, chars_) { - let chars = (chars_) ? chars_ : 2 + let chars = (chars_) ? chars_ : 8 if (!number) { return '' } @@ -32,4 +33,4 @@ export default class Format { } return number } -} \ No newline at end of file +} diff --git a/test/model/testFormat.js b/test/model/testFormat.js index fa6b9ea..a415518 100644 --- a/test/model/testFormat.js +++ b/test/model/testFormat.js @@ -3,22 +3,22 @@ import Format from './../../src/Format' describe('Testing formatter', () => { it('format.money', async () => { - assert(Format.money(1000) === '1,000') + assert(Format.money(1000) === '1,000.00') assert(Format.money(null) === '') }) it('format.percent', async () => { - assert(Format.bitcoin(99.01) === '99.01') - assert(Format.bitcoin(1) === '1.00') - assert(Format.bitcoin(0.001) === '0.00') - assert(Format.bitcoin(null) === '') + assert(Format.percent(99.01) === '99.0') + assert(Format.percent(1) === '1.0') + assert(Format.percent(0.001) === '0.0') + assert(Format.percent(null) === '') }) it('format.bitcoin', async () => { - assert(Format.bitcoin(1000.01) === '1000.01') - assert(Format.bitcoin(1000) === '1000.00') + assert(Format.bitcoin(0.123456789) === '0.12345679') + assert(Format.bitcoin(1) === '1.00000000') assert(Format.bitcoin(null) === '') }) it('format.addPlusSign', async () => { assert(Format.addPlusSign('100') === '+100') assert(Format.addPlusSign('-100') === '-100') }) -}) \ No newline at end of file +})