Added delta instead of avg, and formatted the code to re-use already existing code.

This commit is contained in:
Owaise committed 2025-08-12 23:48:47 +05:30
1 parent 355a445ead
commit e27cc8a12b
7 files changed
+201 -60

No files matched your search

@@ -57,7 +57,7 @@ const useHardwareUtils = () => {
if (GB >= 1) {
return (
<>
{Number(GB.toFixed(0))}
{Number(GB.toFixed(2))}
{space ? " " : ""}
<Typography component="span">{t("gb")}</Typography>
</>
@@ -65,7 +65,7 @@ const useHardwareUtils = () => {
} else {
return (
<>
{Number(MB.toFixed(0))}
{Number(MB.toFixed(2))}
{space ? " " : ""}
<Typography component="span">{t("mb")}</Typography>
</>
@@ -73,6 +73,26 @@ const useHardwareUtils = () => {
}
};
const formatBytesString = (bytes, space = false) => {
if (
bytes === undefined ||
bytes === null ||
typeof bytes !== "number" ||
bytes === 0
) {
return `0${space ? " " : ""}${t("gb")}`;
}
const GB = bytes / (1024 * 1024 * 1024);
const MB = bytes / (1024 * 1024);
if (GB >= 1) {
return `${Number(GB.toFixed(2))}${space ? " " : ""}${t("gb")}`;
} else {
return `${Number(MB.toFixed(2))}${space ? " " : ""}${t("mb")}`;
}
};
/**
* Converts a decimal value to a percentage
*
@@ -134,6 +154,7 @@ const useHardwareUtils = () => {
decimalToPercentage,
buildTemps,
getDimensions,
formatBytesString,
};
};