aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2020-02-03 09:46:48 +0100
committerJoris2020-02-03 09:46:48 +0100
commitf94ae4f8e81590048ddc61c16300c10643673df5 (patch)
treeff78118fd27bd16ae6093e690d7483fabc17e2ae
parented30773e7963d9e70902d834af97937f6f0f9869 (diff)
Keep only the first 2 decimals of the parsed number
-rw-r--r--main.ts4
1 files 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)
}
}