diff options
author | Joris | 2020-02-03 09:46:48 +0100 |
---|---|---|
committer | Joris | 2020-02-03 09:46:48 +0100 |
commit | f94ae4f8e81590048ddc61c16300c10643673df5 (patch) | |
tree | ff78118fd27bd16ae6093e690d7483fabc17e2ae | |
parent | ed30773e7963d9e70902d834af97937f6f0f9869 (diff) |
Keep only the first 2 decimals of the parsed number
-rw-r--r-- | main.ts | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -36,7 +36,7 @@ const inputs = setInputs(itemEntries) inputs.map(input => { input.node.oninput = e => { if (e.target !==null) { - const parsed: ParsedNumber | undefined = parseNumber((e.target as HTMLInputElement).value) + const parsed = parseNumber((e.target as HTMLInputElement).value) if (parsed !== undefined && parsed.before === '' && parsed.after === '') { const factor = parsed.number / input.number @@ -152,7 +152,7 @@ function parseNumber(str: string): ParsedNumber | undefined { return { before: str.substring(0, start), - number: parseFloat(integerPart + (decimalPart !== '' ? '.' + decimalPart : '')), + number: parseFloat(integerPart + (decimalPart !== '' ? '.' + decimalPart.substring(0, 2) : '')), after: str.substring(end, str.length) } } |