BUGFIX: formatNumber throws an error if suffixStart is too low (#957)

This commit is contained in:
TheAimMan 2024-01-07 08:14:02 -05:00 committed by GitHub
parent dd9ace7891
commit 9827fda4a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -113,8 +113,11 @@ export function formatNumber(n: number, fractionalDigits = 3, suffixStart = 1000
// Special handling for Infinities
if (nAbs === Infinity) return n < 0 ? "-∞" : "∞";
if (suffixStart < 1000) {
throw new Error("suffixStart must be greater than or equal to 1000");
}
// Early return for non-suffix
// Early return for non-suffix or if number and suffix are 0
if (nAbs < suffixStart) {
if (isInteger) return basicFormatter.format(n);
return getFormatter(fractionalDigits).format(n);