This commit is contained in:
Fredrik Burmester
2024-09-19 21:23:38 +02:00
parent cc97acbd4f
commit b7465a94e9

19
utils/bToMb.ts Normal file
View File

@@ -0,0 +1,19 @@
/**
* Convert bits to megabits or gigabits
*
* Return nice looking string
* If under 1000Mb, return XXXMB, else return X.XGB
*/
export function convertBitsToMegabitsOrGigabits(bits?: number | null): string {
if (!bits) return "0MB";
const megabits = bits / 1000000;
if (megabits < 1000) {
return Math.round(megabits) + "MB";
} else {
const gigabits = megabits / 1000;
return gigabits.toFixed(1) + "GB";
}
}