Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ export const toAmount = (satoshis, unit) => {
if (!Number.isInteger(satoshis) || !UNITS[unit]) {
throw new Error('Invalid input!');
}
return (satoshis / UNITS[unit].denominator).toString();
const num = satoshis / UNITS[unit].denominator;
return num.toLocaleString('en-US', {
useGrouping: false,
maximumFractionDigits: 8,
});
};

/**
Expand Down
20 changes: 20 additions & 0 deletions test/unit/helper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,26 @@ describe('Helpers Unit Tests', () => {
const num = helpers.toAmount(0, 'btc');
expect(num, 'to equal', '0');
});

it('should work for 1', () => {
const num = helpers.toAmount(1, 'btc');
expect(num, 'to equal', '0.00000001');
});

it('should work for 10', () => {
const num = helpers.toAmount(10, 'btc');
expect(num, 'to equal', '0.0000001');
});

it('should work for 100', () => {
const num = helpers.toAmount(100, 'btc');
expect(num, 'to equal', '0.000001');
});

it('should work for 1000', () => {
const num = helpers.toAmount(1000, 'btc');
expect(num, 'to equal', '0.00001');
});
});

describe('calculateExchangeRate()', () => {
Expand Down