From 8baa1b6f75f08ff7b3f6b448aa9434681fea4011 Mon Sep 17 00:00:00 2001 From: Jonas <jonas.zohren@tu-dortmund.de> Date: Tue, 23 Feb 2021 12:44:50 +0100 Subject: [PATCH] round to two digits while displaying numbers --- src/RowWorkItem.svelte | 10 +++++----- src/SumRow.svelte | 8 ++++---- src/utils.ts | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/RowWorkItem.svelte b/src/RowWorkItem.svelte index c561e27..9248a31 100644 --- a/src/RowWorkItem.svelte +++ b/src/RowWorkItem.svelte @@ -1,6 +1,6 @@ <script lang="ts"> import { calculateE, calculateS, calculateV } from "./estimator"; - import { roundOne } from "./utils"; + import { roundTwo } from "./utils"; export let a: number export let b: number @@ -27,8 +27,8 @@ <td class="tg-0lax"> <input type="number" class="c-input" bind:value="{b}"> </td> - <td class="tg-0lax">{hideNull(roundOne(E))}</td> - <td class="tg-0lax">{hideNull(roundOne(S))}</td> - <td class="tg-0lax">{hideNull(roundOne(SEPercent))}%</td> - <td class="tg-0lax">{hideNull(roundOne(V))}</td> + <td class="tg-0lax">{hideNull(roundTwo(E))}</td> + <td class="tg-0lax">{hideNull(roundTwo(S))}</td> + <td class="tg-0lax">{hideNull(roundTwo(SEPercent))}%</td> + <td class="tg-0lax">{hideNull(roundTwo(V))}</td> </tr> \ No newline at end of file diff --git a/src/SumRow.svelte b/src/SumRow.svelte index 7c76aa6..2c6748c 100644 --- a/src/SumRow.svelte +++ b/src/SumRow.svelte @@ -1,7 +1,7 @@ <script lang="ts"> import type { WorkPackage } from "./estimator"; import { calculateSSum, calculateESum, calculateVSum } from './estimator'; - import { roundOne, sumIgnoreNonNumbers } from "./utils"; + import { roundTwo, sumIgnoreNonNumbers } from "./utils"; export let workPackages: WorkPackage[] export let r: number = NaN; @@ -18,14 +18,14 @@ ∑ {sumIgnoreNonNumbers(workPackages.map(workPackage => workPackage.b))} </td> <td class="tg-0lax"> - ∑ {roundOne(calculateESum(workPackages, r))} + ∑ {roundTwo(calculateESum(workPackages, r))} </td> <td class="tg-0lax"> - {roundOne(calculateSSum(workPackages, u))} + {roundTwo(calculateSSum(workPackages, u))} </td> <td class="tg-0lax"> </td> <td class="tg-0lax"> - ∑ {roundOne(calculateVSum(workPackages, u))} + ∑ {roundTwo(calculateVSum(workPackages, u))} </td> </tr> \ No newline at end of file diff --git a/src/utils.ts b/src/utils.ts index 57ec0a2..21ada1b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,10 +1,10 @@ /** - * Rounds a number to one digit after the period dot or null, if the input is not a number + * Rounds a number to two digits after the period dot or null, if the input is not a number * @param n number to round */ -export function roundOne(n: number): number | null { +export function roundTwo(n: number): number | null { if (typeof n === "number" && !isNaN(n)) { - return Math.round(n * Math.pow(10, 1)) / Math.pow(10, 1); + return Math.round(n * Math.pow(10, 2)) / Math.pow(10, 2); } else { return null; } -- GitLab