Skip to content

Commit a6c9ad2

Browse files
fix: formatNumber does not return string if Infinity or NaN
1 parent 93ac021 commit a6c9ad2

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/numbers/format-number.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function formatNumber(number, format = NUMBER_PLACEHOLDER, locale
1010
}
1111

1212
if (!isFinite(number)) {
13-
return number;
13+
return String(number);
1414
}
1515

1616
const info = localeInfo(locale);

test/numbers.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ describe('formatNumber', () => {
5050
expect(formatNumber(undefined)).toEqual("");
5151
});
5252

53-
it('should return value if not finite value is passed', () => {
54-
expect(formatNumber(Infinity)).toBe(Infinity);
53+
it('should return value as string if not finite value is passed', () => {
54+
expect(formatNumber(Infinity)).toBe(String(Infinity));
55+
expect(formatNumber(NaN)).toBe(String(NaN));
5556
expect(formatNumber("foo")).toEqual("foo");
5657
});
5758

0 commit comments

Comments
 (0)