About decimal-js
The decimal-js skill guides developers using decimal.js v10 for arbitrary-precision decimal arithmetic. It covers configuration, rounding, money-safe patterns, serialization, and advanced math, emphasizing string construction, immutable instances, and isolated configuration with clone.
Key features
- 01Guide arbitrary-precision decimal arithmetic
- 02Configure precision and rounding modes
- 03Handle money and serialization
- 04Isolate configuration with clone
- 05Explain advanced math and library choices
Use cases
- 01Implement currency calculations without floating-point errors
- 02Round values to specified decimal places
- 03Transfer decimal values through JSON or storage
- 04Isolate Decimal settings across libraries or domains
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ dobroslavradosavljevic/ skills --skill decimal-jsAfter installing, type/decimal-jsin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
agents/openai.yamlreferences/advanced-ecosystem.mdarithmetic-api.mdconfig-rounding.mdmoney-serialization.mdpitfalls.mdsetup-core.mdsource-map.mdDetails
From the project READMEdecimal.js
Use this skill for decimal.js v10 arbitrary-precision decimal arithmetic: construction, config, rounding, money-safe patterns, serialization, and advanced math.
Workflow
- Inspect the local surface before changing code:
- Package:
decimal.js(and siblingsdecimal.js-light,bignumber.js,big.jsif present). - Version: target v10 (current
10.6.0); bundleddecimal.d.ts(BigInt in types since 10.6.0). - Domain: money/currency, scientific, or general — this drives
cloneconfig and whether significant-digitprecisionalone is enough. - Imports: default or named
Decimalfrom"decimal.js".
- Package:
- Refresh docs when versions are unclear or work touches rounding, money, trig, or library isolation. Start from source-map.md.
- Route deeper detail:
- Install, constructor, immutability, Value types: setup-core.md.
- Arithmetic, compare, format, static helpers: arithmetic-api.md.
set/config/clone, rounding modes, modulo: config-rounding.md.- Money, JSON/SSR/store transport: money-serialization.md.
- Trig, random/crypto, light vs full, MikeMcl ecosystem: advanced-ecosystem.md.
- Anti-patterns and upgrades: pitfalls.md.
- Match the project's constructor style (
Decimalvs domainclone). Do not call globalDecimal.setinside published libraries. - Verify with typecheck plus tests for string construction, rounding mode,
toDP/toFixed, and serialization round-trips.
Library Decision Tree
Need trig / ln / exp / non-integer pow / wide exponents?
→ decimal.js (this skill)
Exact add/mul until division, finance-first, smaller API?
→ consider bignumber.js (author guidance) — or stay on decimal.js with Money clone + toDP
Tiny bundle, basic DP only?
→ big.js or decimal.js-light
Using decimal.js for money anyway?
→ Decimal.clone({ precision: 28, rounding: … }) + construct from strings + round once with toDP/toFixed
Core Judgment
- Construct from strings (or BigInt / Decimal) for money and multi-digit values. Never
new Decimal(0.1 + 0.2)or Number arithmetic first. - Instances are immutable. Chain methods; do not expect in-place mutation.
precision= significant digits for (almost) all arithmetic results — not currency decimal places. UsetoDecimalPlaces/toDP(ortoFixedfor strings) for fixed fractional places.- Prefer
Decimal.clone({…})for libraries and multi-domain apps. UseDecimal.setonly for app-wide boot config. - Value equality:
.eq/.cmp, never===/==. - Serialize as strings (
toJSON/toFixed/toString). AvoidtoNumber()for money or persisted values. - Default rounding is
ROUND_HALF_UP(4). Pick explicitly for finance (HALF_UP/HALF_EVEN/ jurisdiction rules). - Configure via
set/config/clone— never assignDecimal.precision = …directly (skips validation).
Verification
Prefer repository-owned commands. Cover the relevant subset:
bun pm ls decimal.js(and light / big / bignumber if migrating).- Typecheck for
Decimal.Value,Decimal.Config, clone constructors. - Tests: string vs number construction,
eqvs===,toDP/toFixedrounding modes, penny-allocation / tax edges, JSON hydrate (new Decimal(dto.amount)), signed zero if relevant. - Bundle/size check only when choosing light vs full.
Report which checks ran, which did not, and version/config assumptions that remain.