Skip to content
Snippets Groups Projects
Commit 8baa1b6f authored by Jonas Zohren's avatar Jonas Zohren :speech_balloon:
Browse files

round to two digits while displaying numbers

parent 75a9060c
Branches
No related tags found
No related merge requests found
Pipeline #15629 passed
<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
<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
/**
* 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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment