force temperatures in degrees to always show 1 decimal place

This commit is contained in:
proddy
2021-11-14 16:14:29 +01:00
parent d7576ebda1
commit 9d9ac4ed9e

View File

@@ -122,7 +122,7 @@ export const formatDuration = (duration_min: number) => {
return formatted; return formatted;
}; };
function formatValue(value: any, uom: number, digit: number) { function formatValue(value: any, uom: number) {
switch (uom) { switch (uom) {
case DeviceValueUOM.HOURS: case DeviceValueUOM.HOURS:
return value ? formatDuration(value * 60) : '0 hours'; return value ? formatDuration(value * 60) : '0 hours';
@@ -134,9 +134,10 @@ function formatValue(value: any, uom: number, digit: number) {
} }
return value; return value;
case DeviceValueUOM.DEGREES: case DeviceValueUOM.DEGREES:
// always show with one decimal place
return ( return (
new Intl.NumberFormat(undefined, { new Intl.NumberFormat(undefined, {
minimumFractionDigits: digit minimumFractionDigits: 1
}).format(value) + }).format(value) +
' ' + ' ' +
DeviceValueUOM_s[uom] DeviceValueUOM_s[uom]
@@ -410,7 +411,7 @@ class EMSESPDataForm extends Component<
</TableCell> </TableCell>
<TableCell align="left">{sensorData.i}</TableCell> <TableCell align="left">{sensorData.i}</TableCell>
<TableCell align="right"> <TableCell align="right">
{formatValue(sensorData.t, DeviceValueUOM.DEGREES, 1)} {formatValue(sensorData.t, DeviceValueUOM.DEGREES)}
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))}
@@ -446,7 +447,7 @@ class EMSESPDataForm extends Component<
Analog Input Analog Input
</TableCell> </TableCell>
<TableCell align="right"> <TableCell align="right">
{formatValue(data.analog, DeviceValueUOM.MV, 0)} {formatValue(data.analog, DeviceValueUOM.MV)}
</TableCell> </TableCell>
</TableRow> </TableRow>
</TableBody> </TableBody>
@@ -601,7 +602,7 @@ class EMSESPDataForm extends Component<
{item.n} {item.n}
</TableCell> </TableCell>
<TableCell padding="none" align="right"> <TableCell padding="none" align="right">
{formatValue(item.v, item.u, 0)} {formatValue(item.v, item.u)}
</TableCell> </TableCell>
</TableRow> </TableRow>
))} ))}