Converting the amount of data in bytes to other units with formatting

Displays the file size in readable form, in specified or autodetected units.


size - file size in bytes

formatType - defines in what units the result will be displayed (byte, MB, GB, TB, Auto)
If sfAuto is specified, the unit will depend on the file size, for example, if the size is more than a megabyte, but less than a gigabyte, the result will be displayed in megabytes

precision - the precision of the result, i.e. the number of digits after the decimal point.


Formatted file size string:

formatBytes(fileSize, sfAuto, 2) - result: 8.18 GB
formatBytes(fileSize, sfMB, 2) - result: 8 377.69 MB

Author: admin