Skip to content

Commit 0cc5f24

Browse files
committed
Add formatting of PV values
1 parent e1f03bb commit 0cc5f24

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

app/components/Block.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ export default function Block({
3636
pvChangedIndicator.classList.add("text-transparent");
3737
}, 2000);
3838
}
39+
var formattedValue = currentValue
40+
if (typeof currentValue === 'string') {
41+
var formattedValue: number = +currentValue
42+
}
43+
if (isNaN(formattedValue)) {
44+
var formattedValue = currentValue
45+
} else {
46+
if (pv.units != null && formattedValue != 0 && (formattedValue < 0.001 || formattedValue > 10000)) {
47+
var formattedValue = formattedValue.toExponential()
48+
} else {
49+
var formattedValue = formattedValue.toPrecision()
50+
}
51+
}
3952

4053
const minimum_date_to_be_shown = 631152000; // This is what PVWS thinks epoch time is for some reason. don't bother showing it as the instrument wasn't running EPICS on 01/01/1990
4154
return (
@@ -69,7 +82,7 @@ export default function Block({
6982
className={pv.severity != "NONE" ? "text-red-400" : ""}
7083
>
7184
{showAdvanced && "Readback: "}
72-
{pv.value} {pv.units != null && pv.units}
85+
{formattedValue} {pv.units != null && pv.units}
7386
</span>
7487
<svg
7588
id={pv.human_readable_name + "_CIRCLE"}

0 commit comments

Comments
 (0)