Skip to content

Commit cce552e

Browse files
authored
Merge pull request #1176 from cmu-delphi/sgratzl/fix_formatting
fix Cornercase in rounding
2 parents bf04523 + e16c030 commit cce552e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/components/KPIValue.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
export let loading = false;
1313
1414
$: scaled = value != null && !Number.isNaN(value) ? value * factor : null;
15+
$: digitsPow = Math.pow(10, digits);
16+
$: roundedValue = Math.round(Math.abs(scaled) * digitsPow);
1517
1618
$: hasFraction = loading || (scaled != null && digits > 0 && Math.floor(scaled) !== scaled);
17-
$: base = loading ? '00' : scaled == null ? 'N/A' : Math.floor(scaled);
18-
$: digitsPow = Math.pow(10, digits);
19-
$: fraction = !loading && hasFraction ? Math.round(Math.abs(scaled) * digitsPow) % digitsPow : 0;
19+
$: base = loading ? '00' : scaled == null ? 'N/A' : Math.floor(roundedValue / digitsPow);
20+
$: fraction = !loading && hasFraction ? roundedValue % digitsPow : 0;
2021
</script>
2122

2223
<KPI text={base.toLocaleString()} sub={hasFraction ? `.${fraction}` : null} {loading} />

0 commit comments

Comments
 (0)