Skip to content

Instantly share code, notes, and snippets.

@muvaf
Last active October 13, 2023 16:52
Show Gist options
  • Save muvaf/121ecf9f29e525f210ba32103e2a7808 to your computer and use it in GitHub Desktop.
Save muvaf/121ecf9f29e525f210ba32103e2a7808 to your computer and use it in GitHub Desktop.
Show file size in human readable format in a Retool table
// 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