Skip to content

Commit 167e59e

Browse files
committed
util.inspect: fix numericSeparator for scientific notation numbers
When numericSeparator: true is set, util.inspect produces corrupted output like '1e-.1e-_7' for numbers in scientific notation. The fix adds an early return in formatNumber() for scientific notation numbers (containing 'e') before the decimal-split + numeric separator logic runs. Fixes #62981
1 parent bb85d23 commit 167e59e

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

lib/internal/util/inspect.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,11 @@ function formatNumber(fn, number, numericSeparator) {
22102210
return fn(numberString, 'number');
22112211
}
22122212

2213+
// Scientific notation cannot have numeric separators applied sensibly
2214+
if (StringPrototypeIncludes(numberString, 'e')) {
2215+
return fn(numberString, 'number');
2216+
}
2217+
22132218
const decimalIndex = StringPrototypeIndexOf(numberString, '.');
22142219
const integerPart = StringPrototypeSlice(numberString, 0, decimalIndex);
22152220
const fractionalPart = StringPrototypeSlice(numberString, decimalIndex + 1);

0 commit comments

Comments
 (0)