MCPcopy Index your code
hub / github.com/nodejs/node / formatNumber

Function formatNumber

lib/internal/util/inspect.js:2191–2223  ·  view source on GitHub ↗
(fn, number, numericSeparator)

Source from the content-addressed store, hash-verified

2189const remainingText = (remaining) => `... ${remaining} more item${remaining > 1 ? 's' : ''}`;
2190
2191function 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 }
2197 if (!numericSeparator) {
2198 return fn(`${number}`, 'number');
2199 }
2200
2201 const numberString = String(number);
2202 const integer = MathTrunc(number);
2203
2204 if (integer === number) {
2205 if (!NumberIsFinite(number) || StringPrototypeIncludes(numberString, 'e')) {
2206 return fn(numberString, 'number');
2207 }
2208 return fn(addNumericSeparator(numberString), 'number');
2209 }
2210 if (NumberIsNaN(number) || StringPrototypeIncludes(numberString, 'e')) {
2211 return fn(numberString, 'number');
2212 }
2213
2214 const decimalIndex = StringPrototypeIndexOf(numberString, '.');
2215 const integerPart = StringPrototypeSlice(numberString, 0, decimalIndex);
2216 const fractionalPart = StringPrototypeSlice(numberString, decimalIndex + 1);
2217
2218 return fn(`${
2219 addNumericSeparator(integerPart)
2220 }.${
2221 addNumericSeparatorEnd(fractionalPart)
2222 }`, 'number');
2223}
2224
2225function formatBigInt(fn, bigint, numericSeparator) {
2226 const string = String(bigint);

Callers 3

formatRawFunction · 0.70
formatPrimitiveFunction · 0.70
formatNumberNoColorFunction · 0.70

Calls 4

StringClass · 0.85
addNumericSeparatorFunction · 0.85
addNumericSeparatorEndFunction · 0.85
fnFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…