accounting.js
A lightweight, dependency-free JavaScript library for parsing and formatting numbers, money, and currency values.
Repository Health
Technical Analysis
accounting.js is a small utility library that solves the recurring problem of formatting numbers as money, currency amounts, or grouped numbers in JavaScript. It exposes a handful of pure functions - formatNumber, formatMoney, formatColumn, unformat, and toFixed - that convert between raw numeric values and human-readable, locale-configurable strings without pulling in a full internationalization framework.
The library has no runtime dependencies, works identically in the browser and in Node.js (CommonJS and AMD module patterns are both supported), and its behavior is controlled entirely through a plain settings object for currency symbol, decimal separator, thousands separator, and precision. It also works around floating-point rounding quirks in toFixed that are common headaches when handling money values.
What You Get
- formatMoney() for currency-formatted strings with configurable symbol, precision, and separators
- formatNumber() for grouped, comma-separated number formatting independent of currency
- unformat()/parse() to strip formatting and recover the raw numeric value, including bracketed negatives
- formatColumn() to align a list of currency values into a whitespace-padded column
- A toFixed() replacement that avoids common binary floating-point rounding errors
Common Use Cases
- Displaying prices and totals in an e-commerce or invoicing UI
- Formatting financial report figures into aligned currency columns
- Parsing user-entered currency strings back into numeric values for calculations
- Localising number and currency display for different regions without a full i18n library
Under The Hood
Architecture
accounting.js is a single-file IIFE module with no internal layering: a closure exposes a lib object holding a settings config and a small set of internal helpers (isString, isArray, isObject, defaults, map, checkPrecision, checkCurrencyFormat) that the public API methods (unformat, toFixed, formatNumber, formatMoney, formatColumn) build on. There is no dependency injection or external state - all configuration flows through the shared lib.settings object or per-call option objects, and the module-definition block at the end branches on exports/module.exports/AMD define/global root to support CommonJS, AMD, and plain browser script usage from the same source file.
Tech Stack
The library is plain ES5 JavaScript with zero runtime dependencies (package.json declares an empty dependency list) and no build step - the distributed accounting.js and accounting.min.js files are committed directly to the repo rather than generated by a bundler in CI. It ships via npm and Bower with matching manifests, and is consumed as a Node/CommonJS module, an AMD module, or a global window.accounting object.
Code Quality
Test coverage exists as bundled Jasmine and QUnit suites (tests/jasmine, tests/qunit) run through static HTML runners rather than an automated npm test/CI pipeline - no CI configuration is present in the repo. Error handling is deliberately permissive: comments in the source note that invalid input “fails silently” and coerces to 0 rather than throwing, which is a documented but non-strict design choice. There is no linter config, no TypeScript types, and no type checking; naming is consistent camelCase with JSDoc-style comments on every public method.
What Makes It Unique
The standout technical detail is its toFixed() reimplementation, which routes through exponential notation (Number(value + 'e' + precision)) specifically to avoid native toFixed’s binary floating-point rounding bugs - a real, well-known problem for money math in JavaScript. formatColumn() is also a distinguishing feature versus most similar formatters: it right-aligns a list of formatted values by padding with whitespace, useful for monospaced financial reporting output. Otherwise its formatting approach is standard for the era; modern codebases increasingly rely on the native Intl.NumberFormat API for the same job.
Used by 4 apps in this directory
Automatisch
Automation · No Code Platforms
Self-hosted, no-code workflow automation that keeps your data on your own servers—a privacy-first alternative to Zapier with 90+ integrations.
Bigcapital
Invoicing Finance
Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.
Craft CMS
CMS
A developer-first PHP CMS with clean-slate content modeling, auto-generated GraphQL API, and a four-tier edition system that scales from solo projects to enterprise deployments.
Webiny JS
Ecommerce · Blogging · CMS
Open-source, self-hosted CMS on AWS serverless — a TypeScript framework you extend with code, not a product you configure through a UI.