-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumber.ts
31 lines (30 loc) · 935 Bytes
/
number.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { millify } from 'millify';
/**
* Converts a large number to a more readable string format using millify.
*
* @param {number} value - The number to be converted.
* @param {Parameters<typeof millify>[1]} [options] - Optional configuration for millify.
* @returns {string} The formatted string.
*
* @example
* ```typescript
* import { prettyNumberToString } from '@kikiutils/node/number';
*
* const prettyNumber = prettyNumberToString(1234567);
* console.log(prettyNumber); // Output: '1.23m'
*
* // With custom options
* const prettyNumberWithOptions = prettyNumberToString(1234567, { precision: 3 });
* console.log(prettyNumberWithOptions); // Output: '1.235m'
* ```
*/
export function prettyNumberToString(value: number, options?: Parameters<typeof millify>[1]) {
return millify(
value,
{
lowercase: true,
precision: 2,
...options,
},
);
}