I\'m using this function to convert a file size in bytes to a human-readable file size:
function getReadableFileSizeString(fileSizeInBytes) {
var i = -1;
For those who use Angular, there's a package called angular-pipes that has a pipe for this:
File
import { BytesPipe } from 'angular-pipes';
Usage
{{ 150 | bytes }}
{{ 1024 | bytes }}
{{ 1048576 | bytes }}
{{ 1024 | bytes: 0 : 'KB' }}
{{ 1073741824 | bytes }}
{{ 1099511627776 | bytes }}
{{ 1073741824 | bytes : 0 : 'B' : 'MB' }}
Link to the docs.