Skip to content

Commit d87beb8

Browse files
fix(format-number): no decimals when no suffix is used (#43)
1 parent 4c2de07 commit d87beb8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/js/format-number.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function formatNumber(num, decimalPlaces = 1) {
1010
} else if (num >= 1000) {
1111
return (num / 1000).toFixed(decimalPlaces) + 'k';
1212
} else {
13-
return num.toFixed(decimalPlaces);
13+
return num.toString()
1414
}
1515
}
1616

tests/format-number.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ describe('formatNumber function', () => {
1212
[1234567, 2, '1.23M'], // 1.23 million
1313
[1234, 1, '1.2k'], // 1.2 thousand
1414
[1234, 2, '1.23k'], // 1.23 thousand
15-
[123, 1, '123.0'], // 123 with 1 decimal place
16-
[123, 2, '123.00'], // 123 with 2 decimal places
15+
[123, 1, '123'], // 123 with 1 decimal place
16+
[123, 2, '123'], // 123 with 2 decimal places
1717
])('formats %i with %i decimal places as %s', (num, decimalPlaces, expected) => {
1818
expect(formatNumber(num, decimalPlaces)).toBe(expected);
1919
});
2020

2121
test('defaults to 1 decimal place if not provided', () => {
2222
expect(formatNumber(1234567)).toBe('1.2M');
2323
expect(formatNumber(1234)).toBe('1.2k');
24-
expect(formatNumber(123)).toBe('123.0');
24+
expect(formatNumber(123)).toBe('123');
2525
});
2626
});

0 commit comments

Comments
 (0)