Skip to content

util: fix numericSeparator handling for scientific notation#62983

Open
Fifixex wants to merge 1 commit intonodejs:mainfrom
Fifixex:fix-inspect-numeric-separator
Open

util: fix numericSeparator handling for scientific notation#62983
Fifixex wants to merge 1 commit intonodejs:mainfrom
Fifixex:fix-inspect-numeric-separator

Conversation

@Fifixex
Copy link
Copy Markdown

@Fifixex Fifixex commented Apr 27, 2026

This commit fixes incorrect behavior in util.inspect when numericSeparator is enabled and the input number is represented in scientific notation (e.g. 1e-7 or 1e+21).

Previously, scientific notation strings were incorrectly processed by the numeric separator logic, which assumes the presence of a decimal point. This led to malformed output such as:

'1e-.1e-_7'

The issue occurs because the formatting logic attempts to split the numeric string at a decimal point (.), which does not exist in scientific notation. As a result, incorrect string slicing is applied. This change adds a guard for scientific notation strings, ensuring they are returned without applying numeric separator formatting. It also fixes the case where no decimal point exists by treating the value as a plain number string.

Closes: #62981

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Apr 27, 2026
@ljharb ljharb requested a review from BridgeAR April 27, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

util.inspect: incorrect numericSeparator formatting for numbers in scientific notation (e.g. 1e-7)

4 participants