JSPM

fixed-number

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q36581F
  • License MIT

Format numbers, percentages and currencies with a fixed number of digits

Package Exports

  • fixed-number

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 (fixed-number) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fixed-number

Format numbers, percentages and currencies with a fixed number of digits. Succinct wrapper of Intl.NumberFormat defaulting to en-US locale. In terms of functionality it sits between Number.prototype.toFixed and the option-rich (and consequently verbose) Intl.NumberFormat.

npm status node Travis build status AppVeyor build status JavaScript Style Guide Dependency status

Example

const decimal = require('fixed-number')(1, 3)
const percent = require('fixed-number')(2, 1, 'percent')
const usd = require('fixed-number')(2, 2, 'usd')
const eur = require('fixed-number')(3, 0, 'eur')
const custom = require('fixed-number')(1, 1, '+')

console.log(decimal(123456.78900001)) // '123,456.789'
console.log(decimal(NaN)) // '-.---'
console.log(percent(0.2)) // '20.0%'
console.log(usd(19.99)) // '$19.99'
console.log(eur(19.99)) // '€020'
console.log(custom(2)) // '2.0+'

API

format = require('fixed-number')(..)

Arguments:

  • minimumIntegerDigits (number, required)
  • exactFractionDigits (number, required)
  • style (string): 'decimal' (default), 'percent', a ISO 4217 currency code, or a custom suffix.
  • locale (string): defaults to 'en-US' (see Node.js docs for requirements)

Returns a function format that when called with a number, returns a formatted string.

Install

With npm do:

npm install fixed-number

License

MIT © 2017-present Vincent Weevers