Last active
October 13, 2023 16:52
-
-
Save muvaf/121ecf9f29e525f210ba32103e2a7808 to your computer and use it in GitHub Desktop.
Show file size in human readable format in a Retool table
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
// Replace "item" with your variable name. | |
{{ (item / Math.pow(1024, Math.floor(Math.log(item) / Math.log(1024)))).toFixed(2) }} {{ Array.from(['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'])[Math.floor(Math.log(item) / Math.log(1024))] }} | |
/* It'll show like the following: | |
* 42.00 Bytes | |
* 1.09 MB | |
* 2.89 GB | |
*/ | |
// Credit to https://stackoverflow.com/a/34210131/5233252 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment