Socket
Socket
Sign inDemoInstall

@moleculexyz/humanized-numbers

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @moleculexyz/humanized-numbers

display numbers (and bigints) in a more human way


Version published
Maintainers
1
Created

Readme

Source

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

npm i @moleculexyz/humanized-numbers
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.

FAQs

Last updated on 12 Oct 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc