Skip to content

Commit b8df2cd

Browse files
committed
fix: keep scientific expansion coverage stable
1 parent c6c5dcb commit b8df2cd

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/numberUtil.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,16 @@ function expandScientificNotation(parsed: ParsedScientificNotation) {
109109
const initialDecimalIndex = integerDigits || -leadingDecimalZeros;
110110
const decimalIndex = initialDecimalIndex + exponent;
111111

112-
const expanded =
113-
decimalIndex <= 0
114-
? `0.${'0'.repeat(-decimalIndex)}${digits}`
115-
: decimalIndex >= digits.length
116-
? `${digits}${'0'.repeat(decimalIndex - digits.length)}`
117-
: `${digits.slice(0, decimalIndex)}.${digits.slice(decimalIndex)}`;
112+
// eslint-disable-next-line no-useless-assignment
113+
let expanded = '';
114+
115+
if (decimalIndex <= 0) {
116+
expanded = `0.${'0'.repeat(-decimalIndex)}${digits}`;
117+
} else if (decimalIndex >= digits.length) {
118+
expanded = `${digits}${'0'.repeat(decimalIndex - digits.length)}`;
119+
} else {
120+
expanded = `${digits.slice(0, decimalIndex)}.${digits.slice(decimalIndex)}`;
121+
}
118122

119123
return `${negative ? '-' : ''}${expanded}`;
120124
}

0 commit comments

Comments
 (0)