Convert large number to human readable format (K, M, B).
Code
Utilitiesconst units = ['', 'K', 'M', 'B', 'T'];
let i = 0, n = Math.abs(num);
while (n >= 1000 && i < units.length - 1) { n /= 1000; i++; }
return (num < 0 ? '-' : '') + n.toFixed(2) + units[i];Parameters
Number to humanize.
Browser·fetch() may be limited by CORS
More JavaScript Snippets
CSV to Markdown Table
Convert CSV data to a markdown table format for documentation.
Format Bytes (IEC)
Format bytes using IEC units (KiB, MiB, GiB) based on powers of 1024.
Format Credit Card
Format a credit card number with spaces every four digits.
Format File Size
Format bytes to a human readable file size with appropriate units.
Format List
Format an array as a human-readable list with 'and' or 'or' conjunctions.
Format Number Compact
Format a number in compact notation like 1K, 1M, or 1B.