File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2189,11 +2189,12 @@ function addNumericSeparatorEnd(integerString) {
21892189const remainingText = ( remaining ) => `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
21902190
21912191function formatNumber ( fn , number , numericSeparator ) {
2192+ // Format -0 as '-0'. Checking `number === -0` won't distinguish 0 from -0.
2193+ // String(-0) === '0', so this must be checked before any String() conversion.
2194+ if ( ObjectIs ( number , - 0 ) ) {
2195+ return fn ( '-0' , 'number' ) ;
2196+ }
21922197 if ( ! numericSeparator ) {
2193- // Format -0 as '-0'. Checking `number === -0` won't distinguish 0 from -0.
2194- if ( ObjectIs ( number , - 0 ) ) {
2195- return fn ( '-0' , 'number' ) ;
2196- }
21972198 return fn ( `${ number } ` , 'number' ) ;
21982199 }
21992200
Original file line number Diff line number Diff line change @@ -3793,6 +3793,7 @@ assert.strictEqual(
37933793 assert . strictEqual ( util . inspect ( NaN ) , 'NaN' ) ;
37943794 assert . strictEqual ( util . inspect ( Infinity ) , 'Infinity' ) ;
37953795 assert . strictEqual ( util . inspect ( - Infinity ) , '-Infinity' ) ;
3796+ assert . strictEqual ( util . inspect ( - 0 ) , '-0' ) ;
37963797
37973798 assert . strictEqual (
37983799 util . inspect ( new Float64Array ( [ 100_000_000 ] ) ) ,
@@ -3824,6 +3825,9 @@ assert.strictEqual(
38243825 '-123_456_789.123_456_78'
38253826 ) ;
38263827
3828+ // -0 should be formatted as '-0' even with numericSeparator enabled
3829+ assert . strictEqual ( util . inspect ( - 0 , { numericSeparator : true } ) , '-0' ) ;
3830+
38273831 // Regression test for https://github.com/nodejs/node/issues/59376
38283832 // numericSeparator should work correctly for negative fractional numbers
38293833 {
You can’t perform that action at this time.
0 commit comments