Registry / productivity / number-formatter

number-formatter

JSON →
library1.2.0jsnpmunverified

A lightweight and fast standalone JavaScript number formatter, version 1.2.0. It supports standard number formatting masks like '#,##0.00', custom grouping and decimal symbols, auto-rounding, and prefix/suffix (with restrictions). The library is less than 1.2 KB minified and has no dependencies. It is available as an npm package and via Bower, with UMD support (AMD, CommonJS, global). Key differentiators: tiny footprint, simple API, and flexible mask syntax. Not intended for scientific notation or date formatting.

npm install number-formatter
INSTALL
IMPORT
SIG · NUMBER-FORMATTER
N
number-formatter
productivityjavascriptv1.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

numberFormatter
import numberFormatter from 'number-formatter'
const { numberFormatter } = require('number-formatter');
Default export only. CommonJS: const numberFormatter = require('number-formatter')
numberFormatter
const numberFormatter = require('number-formatter')
import { numberFormatter } from 'number-formatter'
CommonJS: the package exports the function directly as module.exports
numberFormatter
<script src="number-formatter.min.js"></script> <script>var result = numberFormatter('#,##0.00', 1234.5);</script>
<script>import numberFormatter from 'number-formatter';</script>
Browser: global variable 'numberFormatter' after including script

Shows basic usage of numberFormatter with different masks: comma grouping, currency, European separators, and rounding.

import numberFormatter from 'number-formatter'; // Basic formatting with comma grouping and two decimals const result = numberFormatter('#,##0.00', 1234567.891); console.log(result); // "1,234,567.89" // Currency format with prefix and negative handling const currency = numberFormatter('$ #,###.00', -1234567.89); console.log(currency); // "$ -1,234,567.89" // Custom grouping and decimal symbols (e.g., European style) const european = numberFormatter('#.##0,00', 1234567.89); console.log(european); // "1.234.567,89" // Rounding to 4 decimal places const piFormatted = numberFormatter('0.0000', Math.PI); console.log(piFormatted); // "3.1416"
Debug
Known issues
gotchaSingle symbol treated as decimal separator, not group separator (e.g., '#,###' outputs '1234567,890' instead of '1,234,567')
fix
To force a single symbol as group separator, add a trailing dot: '#,###.'
affects: >=1.0.0
gotchaPrefix/suffix cannot contain digits, dashes, or plus signs
fix
Use concatenation: '$' + numberFormatter('#,##0.00', val) or numberFormatter('#,##0.00', val) + 'USD'
affects: >=1.0.0
deprecatedBower support is deprecated and the package is best consumed via npm
fix
Use npm install instead of bower install
affects: >=1.1.5
gotchaZero value with negation mask may still show negative sign in older versions <1.1.2
fix
Upgrade to >=1.1.2 which removes negative sign from zero results
affects: <1.1.2
gotchaNo scientific or engineering notation supported
fix
Avoid using with very large/small numbers; consider using Number.prototype.toExponential or a dedicated library
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: numberFormatter is not a function
Incorrect import style (e.g., named import instead of default) or missing require
fix
Use: const numberFormatter = require('number-formatter');
Expected output '1,234,567' but got '1234567,890'
Single symbol mask like '#,###' is interpreted as decimal separator
fix
Add trailing dot to force group separator: '#,###.'
numberFormatter('#,##0.00', 'abc') returns NaN
Non-numeric input string
fix
Ensure the second argument is a number: use parseFloat or Number conversion first
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
28 hits · last 30 days
node
22
Amazon
1
OpenAI (training)
1
Resources
number-formatter — npm install number-formatter · libregistry