Socket
Socket
Sign inDemoInstall

format-num

Package Overview
Dependencies
2
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-num

Format numbers.


Version published
Maintainers
2
Weekly downloads
7,353
decreased by-9.07%
Install size
1.36 MB

Weekly downloads

Readme

Source

format-num

NPM Package Build Status js-standard-style

format-num is a JavaScript component to format numbers to strings. Used in Exodus Ethereum Wallet.

Install

npm install --save format-num

Notes

  • Must have a JavaScript environment with Object.assign and Intl.NumberFormat. In Node.js, this is at least v4. You can install in older environments, you'll just need to polyfill.

Usage

formatNum

Signature: formatNum(value, [options])

Parameters:

  • value: Value to convert. Will pass through parse-num first. Will coerce anything to a number.
  • options: optional object parameter to specify options. Appending Digits is not necessary. You can also shorten maximum to max and minimum to min. Adds one more option nanZero, which when the number is NaN, if it should be coerced to 0 - defaults to true i.e. NaN => '0'.

Returns:

The string representation of the number.

Example:

const formatNum = require('format-num')

console.log(formatNum(10000000.15)) // => 10,000,000.15
console.log(formatNum('10000000.15')) // => 10,000,000.15

console.log(formatNum(0.0000000000044535, { maxSignificant: 2 })) // => 0.0000000000045
console.log(formatNum(0, { minFraction: 2, maxFraction: 2 }))  // => 0.00

console.log(formatNum(null)) // => 0
console.log(formatNum(null, { nanZero: false })) // => NaN
  • parse-num: Parse anything into a number. A dependency of this library.
  • number-unit: Numbers with units. Easily convert numbers to from different units.

License

MIT

Keywords

FAQs

Last updated on 08 Feb 2024

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