Created
March 29, 2021 02:00
-
-
Save wewindy/1e716ad59db94bbef2562ac5f2638665 to your computer and use it in GitHub Desktop.
return a string that friendly print file size.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function friendlyFileSize(sizeInBytes) { | |
if(sizeInBytes < 1024) { | |
return `${sizeInBytes} Bytes`; | |
} else if(sizeInBytes >= 1024 && sizeInBytes < 1048576) { | |
return `${(sizeInBytes/1024).toFixed(2)} KB`; | |
} else if(sizeInBytes >= 1048576) { | |
return `${(sizeInBytes/1048576).toFixed(2)} MB`; | |
} | |
} | |
// friendlyFileSize(123490421) | |
// "117.77 MB" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment