diff --git a/src/js/format-number.js b/src/js/format-number.js index 3bea97d..f31a1ed 100644 --- a/src/js/format-number.js +++ b/src/js/format-number.js @@ -10,7 +10,7 @@ function formatNumber(num, decimalPlaces = 1) { } else if (num >= 1000) { return (num / 1000).toFixed(decimalPlaces) + 'k'; } else { - return num.toFixed(decimalPlaces); + return num.toString() } } diff --git a/tests/format-number.test.js b/tests/format-number.test.js index 4e2104e..c26a8aa 100644 --- a/tests/format-number.test.js +++ b/tests/format-number.test.js @@ -12,8 +12,8 @@ describe('formatNumber function', () => { [1234567, 2, '1.23M'], // 1.23 million [1234, 1, '1.2k'], // 1.2 thousand [1234, 2, '1.23k'], // 1.23 thousand - [123, 1, '123.0'], // 123 with 1 decimal place - [123, 2, '123.00'], // 123 with 2 decimal places + [123, 1, '123'], // 123 with 1 decimal place + [123, 2, '123'], // 123 with 2 decimal places ])('formats %i with %i decimal places as %s', (num, decimalPlaces, expected) => { expect(formatNumber(num, decimalPlaces)).toBe(expected); }); @@ -21,6 +21,6 @@ describe('formatNumber function', () => { test('defaults to 1 decimal place if not provided', () => { expect(formatNumber(1234567)).toBe('1.2M'); expect(formatNumber(1234)).toBe('1.2k'); - expect(formatNumber(123)).toBe('123.0'); + expect(formatNumber(123)).toBe('123'); }); });