From f94ae4f8e81590048ddc61c16300c10643673df5 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 3 Feb 2020 09:46:48 +0100 Subject: Keep only the first 2 decimals of the parsed number --- main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.ts b/main.ts index a101d9f..ab3f2bf 100644 --- a/main.ts +++ b/main.ts @@ -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) } } -- cgit v1.2.3