+
${roundedValue}%
@@ -155,6 +172,7 @@ class HassioSystemMetrics extends LitElement {
}
.value {
width: 42px;
+ padding-right: 4px;
}
`,
];
diff --git a/src/util/bytes-to-string.ts b/src/util/bytes-to-string.ts
new file mode 100644
index 0000000000..72829b15da
--- /dev/null
+++ b/src/util/bytes-to-string.ts
@@ -0,0 +1,10 @@
+export const bytesToString = (value = 0, decimals = 2): string => {
+ if (value === 0) {
+ return '0 Bytes';
+ }
+ const k = 1024;
+ decimals = decimals < 0 ? 0 : decimals;
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
+ const i = Math.floor(Math.log(value) / Math.log(k));
+ return `${parseFloat((value / k ** i).toFixed(decimals))} ${sizes[i]}`;
+}