Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

round to 1 decimal by default

Vincent83e6370d7206
diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.ts
index c746c1217..2597ca5a5 100644
--- a/ui/component/or-attribute-card/src/index.ts
+++ b/ui/component/or-attribute-card/src/index.ts
@@ -647,16 +647,17 @@ export class OrAttributeCard extends LitElement {
protected getFormattedValue(value: number): {value: number, unit: string, formattedValue: string} {
const format = getMetaValue(MetaItemType.FORMAT, this.asset.attributes![this.attributeName!], undefined);
+ const roundedVal = +value.toFixed(1); // + operator prevents str return
if (!format) {
- return {value: value, unit: "", formattedValue: value.toString()};
+ return {value: roundedVal, unit: "", formattedValue: value.toString()};
}
const unit = format.split(" ").pop();
return {
- value: value,
+ value: roundedVal,
unit: unit,
- formattedValue: i18next.t(format, { postProcess: "sprintf", sprintf: [value] }).trim()
+ formattedValue: i18next.t(format, { postProcess: "sprintf", sprintf: [roundedVal] }).trim()
};
}