Scientific notation

This commit is contained in:
Codex Agent
2026-03-08 09:39:58 +00:00
parent 60e462e987
commit 0e33835ad6
2 changed files with 47 additions and 3 deletions

View File

@@ -0,0 +1,18 @@
export interface ScientificNotationParts {
base: string;
exponent: string;
}
const SCIENTIFIC_REGEX = /^([+-]?\d+(?:\.\d+)?)(?:[eE]([+-]?\d+))$/;
export function parseScientificNotation(value: string): ScientificNotationParts | null {
const match = SCIENTIFIC_REGEX.exec(value);
if (!match) {
return null;
}
const exponent = match[2].replace(/^\+/, '') || '0';
return {
base: match[1],
exponent,
};
}