ProvenPin Install

big.js precise decimal math: working versions (tested 2026-10-16)

Precise decimal arithmetic with big.js: configure DP and RM, add and divide with different rounding modes, raise integer powers, round values and compare with eq and gt. Proves 0.1 plus 0.2 equals 0.3 offline.

passed5 passed · 0 failed2026-10-16 15:20 UTC
Status
passed
Last passed
2026-10-16 15:20 UTC
Tests
5 / 5
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
big.js@7.0.1@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38923127324

The code

Exactly the files that passed. Your agent can pull them with get_recipe("bigjs-decimal-math") (install), or see them on GitHub.

package.json
{
  "name": "bigjs-decimal-math",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "big.js": "7.0.1"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "noEmit": true,
    "allowImportingTsExtensions": true,
    "types": ["node"]
  },
  "include": ["src", "test"]
}
src/decimal.ts
import Big from "big.js";

export const RoundingMode = {
  down: 0,
  halfUp: 1,
  halfEven: 2,
  up: 3,
} as const;

export type RoundingMode = (typeof RoundingMode)[keyof typeof RoundingMode];

export function configure(dp: number, rm: RoundingMode): void {
  Big.DP = dp;
  Big.RM = rm;
}

export function add(a: string, b: string): Big {
  return new Big(a).plus(b);
}

export function divide(
  a: string,
  b: string,
  rm: RoundingMode = RoundingMode.halfUp,
): Big {
  Big.RM = rm;
  return new Big(a).div(b);
}

export function power(base: string, exponent: number): Big {
  return new Big(base).pow(exponent);
}

export function round(
  value: string,
  dp: number,
  rm: RoundingMode = RoundingMode.halfUp,
): Big {
  return new Big(value).round(dp, rm);
}

export function equals(a: string | Big, b: string | Big): boolean {
  return new Big(a).eq(b);
}

export function greaterThan(a: string | Big, b: string | Big): boolean {
  return new Big(a).gt(b);
}
test/decimal.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import Big from "big.js";
import {
  RoundingMode,
  add,
  configure,
  divide,
  equals,
  greaterThan,
  power,
  round,
} from "../src/decimal.ts";

test("0.1 + 0.2 equals 0.3 with big.js", () => {
  assert.notEqual(0.1 + 0.2, 0.3);
  const sum = add("0.1", "0.2");
  assert.equal(sum.toString(), "0.3");
  assert.equal(equals(sum, "0.3"), true);
  assert.equal(new Big("0.1").plus("0.2").eq("0.3"), true);
});

test("comparisons use eq and gt", () => {
  assert.equal(equals("0.3", "0.30"), true);
  assert.equal(greaterThan("0.31", "0.3"), true);
  assert.equal(greaterThan("0.3", "0.3"), false);
});

test("division honours DP and rounding mode", () => {
  configure(2, RoundingMode.down);
  const down = divide("1", "3", RoundingMode.down);
  const up = divide("1", "3", RoundingMode.up);
  assert.equal(down.toString(), "0.33");
  assert.equal(up.toString(), "0.34");
  assert.notEqual(down.toString(), up.toString());

  configure(4, RoundingMode.halfUp);
  assert.equal(divide("1", "3", RoundingMode.halfUp).toString(), "0.3333");
});

test("pow raises integer exponents precisely", () => {
  assert.equal(power("2", 10).toString(), "1024");
  assert.equal(power("1.5", 3).toString(), "3.375");
});

test("round applies the requested rounding mode", () => {
  assert.equal(round("2.5", 0, RoundingMode.halfUp).toString(), "3");
  assert.equal(round("2.5", 0, RoundingMode.halfEven).toString(), "2");
  assert.equal(round("2.1", 0, RoundingMode.up).toString(), "3");
  assert.equal(round("2.9", 0, RoundingMode.down).toString(), "2");
  assert.equal(round("1.005", 2, RoundingMode.halfUp).toString(), "1.01");
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.