Skip to content

fileSizeFormat

Returns the given file size (in bytes) as a human-readable string.

Parameters

  • bytes::number: Converts it to a human-friendly string via the bytes provided here.
  • decimals::number (Default: 2)
    Named
    : Specifies the number of decimal places to represent.
  • ceil::boolean
    Named
    : If this value is true, the decimal point is removed and the number is rounded up.

Returns

string

Examples

javascript
fileSizeFormat(1000000); // '976.56 KB'
fileSizeFormat(100000000, 3); // '95.367 MB'
fileSizeFormat(100000000, 0, true); // '96 MB'
dart
fileSizeFormat(1000000); // '976.56 KB'
fileSizeFormat(100000000, decimals: 3); // '95.367 MB'
fileSizeFormat(100000000, ceil: true); // '96 MB'

Released under the MIT License