We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4c2de07 commit d87beb8Copy full SHA for d87beb8
src/js/format-number.js
@@ -10,7 +10,7 @@ function formatNumber(num, decimalPlaces = 1) {
10
} else if (num >= 1000) {
11
return (num / 1000).toFixed(decimalPlaces) + 'k';
12
} else {
13
- return num.toFixed(decimalPlaces);
+ return num.toString()
14
}
15
16
tests/format-number.test.js
@@ -12,15 +12,15 @@ 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
17
])('formats %i with %i decimal places as %s', (num, decimalPlaces, expected) => {
18
expect(formatNumber(num, decimalPlaces)).toBe(expected);
19
});
20
21
test('defaults to 1 decimal place if not provided', () => {
22
expect(formatNumber(1234567)).toBe('1.2M');
23
expect(formatNumber(1234)).toBe('1.2k');
24
- expect(formatNumber(123)).toBe('123.0');
+ expect(formatNumber(123)).toBe('123');
25
26
0 commit comments