fix(Utils): formatFrequency method to handle non-finite values and improve frequency formatting

This commit is contained in:
Ivan
2026-04-25 16:30:19 -05:00
parent 8e2f4ee7f7
commit ac64b3ed22
+5 -3
View File
@@ -204,15 +204,17 @@ class Utils {
}
static formatFrequency(hz) {
if (!hz || hz <= 0) {
const n = Number(hz);
if (!Number.isFinite(n) || n <= 0) {
return "0 Hz";
}
const k = 1000;
const rounded = Math.round(n);
const sizes = ["Hz", "kHz", "MHz", "GHz", "THz", "PHz", "EHz", "ZHz", "YHz"];
const i = Math.floor(Math.log(hz) / Math.log(k));
const i = Math.floor(Math.log(rounded) / Math.log(k));
return parseFloat(hz / Math.pow(k, i)) + " " + sizes[i];
return parseFloat((rounded / Math.pow(k, i)).toFixed(6)) + " " + sizes[i];
}
static decodeBase64ToUtf8String(base64) {