https://github.com/moleculeprotocol/humanized-numbers
https://github.com/moleculeprotocol/humanized-numbers
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/moleculeprotocol/humanized-numbers
- Owner: moleculeprotocol
- License: mit
- Created: 2023-09-06T13:55:37.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-19T06:09:46.000Z (over 2 years ago)
- Last Synced: 2025-08-29T00:31:34.042Z (10 months ago)
- Language: TypeScript
- Size: 90.8 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# humanized numbers
humanizes numbers aka cuts unnecessary floating point display precision and shows 10exp shortcuts (monetary) like "M","K","B".
Supports bigints, scientific notation, decimal cutting.
zero dependencies
```bash
npm i @moleculexyz/humanized-numbers
```
```ts
import {humanNumber, humanBigint} from '@moleculexyz/humanized-numbers'
expect(humanNumber(1234.567891)).toEqual('1,234.5679')
expect(humanNumber(1200.2345, true, 2)).toEqual('1,200.23')
expect(humanNumber(1_205_860, true)).toEqual('1.2059M')
expect(humanNumber(1_059_424.52, true, 2)).toEqual('1.06M')
//also works with bigints
expect(humanBigint(1205860000000000000000000n, 18, true)).toEqual('1.2059M')
expect(humanBigint(64068284585n, 6, true, 0)).toEqual('64,068')
```
## TODO
Use the user's locale by default. Atm we're using en_US as the default.