Package Exports
- format-num
- format-num/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (format-num) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
format-num
format-num is a JavaScript component to format numbers to strings. Used in Exodus Ethereum Wallet.
Install
npm install --save format-numNotes
- Must have a JavaScript environment with
Object.assignandIntl.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: optionalobjectparameter to specify options. AppendingDigitsis not necessary. You can also shortenmaximumtomaxandminimumtomin. Adds one more optionnanZero, which when the number isNaN, if it should be coerced to0- defaults totruei.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 })) // => NaNRelated
- 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