mirror of
https://github.com/streamyfin/streamyfin.git
synced 2025-08-20 18:37:18 +02:00
chore
This commit is contained in:
19
utils/bToMb.ts
Normal file
19
utils/bToMb.ts
Normal 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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user