Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 75eb427

Browse files
committed
Display only two fraction digits for fiat amount input
1 parent 37d5e38 commit 75eb427

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/helper.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ export const toAmount = (satoshis, settings) => {
9292
const num = settings.displayFiat
9393
? calculateExchangeRate(satoshis, settings)
9494
: satoshis / UNITS[settings.unit].denominator;
95-
const options = { useGrouping: false, maximumFractionDigits: 8 };
95+
const options = {
96+
useGrouping: false,
97+
minimumFractionDigits: settings.displayFiat ? 2 : 0,
98+
maximumFractionDigits: settings.displayFiat ? 2 : 8,
99+
};
96100
return new Intl.NumberFormat('en-US', options).format(num);
97101
};
98102

test/unit/helper.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,31 +363,31 @@ describe('Helpers Unit Tests', () => {
363363
it('should work for number input (fiat)', () => {
364364
settings.displayFiat = true;
365365
const num = helpers.toAmount(100000, settings);
366-
expect(num, 'to equal', '6.89512515');
366+
expect(num, 'to equal', '6.90');
367367
});
368368

369369
it('should use period for decimals values (fiat)', () => {
370370
settings.displayFiat = true;
371371
const num = helpers.toAmount(100000000, settings);
372-
expect(num, 'to equal', '6895.12514652');
372+
expect(num, 'to equal', '6895.13');
373373
});
374374

375375
it('should work for 0 (fiat)', () => {
376376
settings.displayFiat = true;
377377
const num = helpers.toAmount(0, settings);
378-
expect(num, 'to equal', '0');
378+
expect(num, 'to equal', '0.00');
379379
});
380380

381381
it('should work for 1 (fiat)', () => {
382382
settings.displayFiat = true;
383383
const num = helpers.toAmount(1, settings);
384-
expect(num, 'to equal', '0.00006895');
384+
expect(num, 'to equal', '0.00');
385385
});
386386

387387
it('should work for 1000 (fiat)', () => {
388388
settings.displayFiat = true;
389389
const num = helpers.toAmount(1000, settings);
390-
expect(num, 'to equal', '0.06895125');
390+
expect(num, 'to equal', '0.07');
391391
});
392392
});
393393

0 commit comments

Comments
 (0)