EasyPythonJavaScriptTypeScript

Format Bytes (Human-Readable)

Node.jsNumbersFormat

Convert a byte count into a human-readable string using binary units
(1024-based): B, KB, MB, GB, TB.

solve(1536)'1.5 KB'. Round to 1 decimal place. solve(0)'0 B'.

Sample tests

Test #11 KB exact
Input: [1024]
Output: "1 KB"
Test #21.5 KB
Input: [1536]
Output: "1.5 KB"
Test #31 MB
Input: [1048576]
Output: "1 MB"
Test #41 TB
Input: [1099511627776]
Output: "1 TB"
Test #5Zero bytes
Input: [0]
Output: "0 B"