Documentation / @andrew_l/toolkit / humanize
Function: humanize() ​
humanize(
input
,decimals?
):string
Humanizes large numbers into a more readable format using suffixes like K, M, B, T (thousand, million, billion, trillion).
Parameters ​
input ​
The number or string to humanize. If the input is a string, it will be parsed into a number.
string
| number
decimals? ​
number
= 1
The number of decimal places to display. Default is 1.
Returns ​
string
A humanized string representation of the number.
Examples ​
ts
humanize(1000000);
// Returns: '1M'
ts
humanize(1234567890);
// Returns: '1.2B'
ts
humanize(9876543210, 2);
// Returns: '9.88B'
ts
humanize(500);
// Returns: '500'
ts
humanize('1000000');
// Returns: '1M'