Namespace: Units:asFileSize

Units:asFileSize

Source:

Methods

asFileSize(bytes, separatoropt, nullable, precisionopt, nullable, useBinaryBaseopt, nullable) → {String}

Renders a byte number as a human-readable file size with the correct unit.

Switch calculation base by setting useBinaryBase to true. Today, file sizes are usually calculated against a decimal base of 1000, while in the past, a binary base of 1024 was commonly used (and still is today by some software such as Microsoft Windows). In 1998 the IEC standardized byte units to be metric in nature, which is the base assumption of this method.

Parameters:
Name Type Attributes Default Description
bytes Number

file size in bytes to render as string

separator String <optional>
<nullable>
LOCAL_FLOAT_SEPARATOR

the character to separate the fraction in float numbers, will default to the current browser's default for local strings

precision Number <optional>
<nullable>
1

the floating point precision to use for the size

useBinaryBase Boolean <optional>
<nullable>
false

set to true to activate binary calculation and units

Source:
See:
Returns:
the formatted file size
Type
String
Example
asFileSize(1_500_000, ',')
=> '1,5 MB'
asFileSize(1024, '.', 0, true)
=> '1 KiB'