Skip to content

Commit

Permalink
fix(formatter): fix number formatter for exponent=1
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTelanie committed Sep 14, 2018
1 parent 84541a4 commit 77308da
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function formatNumber(nr, digits) {
n.exp += 1;
}

if (n.exp <= 1) {
if (n.exp < 1) {
mant = mant.toString().replace('0.', '');

return `0.${'0'.repeat(Math.max(0, -n.exp))}${mant}`;
Expand Down
3 changes: 3 additions & 0 deletions test/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ describe('formatNumber test.', () => {
assert.equal(formatNumber(0.0000000000000000000000000001), '0.0000000000000000000000000001');
assert.equal(formatNumber(0.00009999999999), '0.0001');
assert.equal(formatNumber(0.00009999), '0.00009999');
assert.equal(formatNumber(2.5), '2.5');
assert.equal(formatNumber(2.9999999999), '3.0');
assert.equal(formatNumber(2.999), '2.999');
assert.equal(formatNumber(257.5657), '257.6');
assert.equal(formatNumber(2575657546445.985), '2575657546446');
});
Expand Down

0 comments on commit 77308da

Please sign in to comment.