Created
August 22, 2019 10:49
-
-
Save IngIeoAndSpare/091f7297622e1d3abd8c1372849ee312 to your computer and use it in GitHub Desktop.
study...
This file contains hidden or 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 convertSize(fileSize, fixed) { | |
| var sizeName = ['Byte','KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB']; | |
| var sizeOffset = Math.round((fileSize.toString().length / 4)); | |
| var sizeReduceArray = [fileSize] | |
| for(var loopCountNum = 0; loopCountNum < sizeOffset; loopCountNum++){ | |
| sizeReduceArray.push(1024); | |
| } | |
| const size = sizeReduceArray.reduce((acc, cur) => acc / cur).toFixed(fixed); | |
| return `${size} ${sizeName[sizeOffset]}`; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment