initial commit
This commit is contained in:
6
src/utils/math/byteToSize.util.ts
Normal file
6
src/utils/math/byteToSize.util.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export function bytesToSize(bytes: number) {
|
||||
const sizes = ["B", "KB", "MB", "GB", "TB"];
|
||||
if (bytes == 0) return "0 Byte";
|
||||
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)).toString());
|
||||
return (bytes / Math.pow(1024, i)).toFixed(1).toString() + " " + sizes[i];
|
||||
}
|
||||
Reference in New Issue
Block a user