mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
util: fix scientific notation formatting
Signed-off-by: Daijiro Wachi <daijiro.wachi@gmail.com> PR-URL: https://github.com/nodejs/node/pull/63823 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
1 parent
b3d0d05b05
commit
60e83d9bfd
2 files changed
+7
-1
No files matched your search
@@ -2207,7 +2207,7 @@ function formatNumber(fn, number, numericSeparator) {
|
||||
}
|
||||
return fn(addNumericSeparator(numberString), 'number');
|
||||
}
|
||||
if (NumberIsNaN(number)) {
|
||||
if (NumberIsNaN(number) || StringPrototypeIncludes(numberString, 'e')) {
|
||||
return fn(numberString, 'number');
|
||||
}
|
||||
|
||||
|
||||
@@ -3848,6 +3848,12 @@ assert.strictEqual(
|
||||
'-0.123_45'
|
||||
);
|
||||
}
|
||||
|
||||
// Numbers in scientific notation should not get malformed separators
|
||||
assert.strictEqual(util.inspect(1e-7, { numericSeparator: true }), '1e-7');
|
||||
assert.strictEqual(util.inspect(1.5e-10, { numericSeparator: true }), '1.5e-10');
|
||||
assert.strictEqual(util.inspect(1.23e-100, { numericSeparator: true }), '1.23e-100');
|
||||
assert.strictEqual(util.inspect(1.23456789e-12, { numericSeparator: true }), '1.23456789e-12');
|
||||
}
|
||||
|
||||
// Regression test for https://github.com/nodejs/node/issues/41244
|
||||
|
||||
Reference in new issue
Block a user