PrimeBrickPrimeBrick
  • Docs
  • Contact
  • MIT License
  • Documentation
  • MCP Server
  • API Catalog
  • Services
  • Libraries
PrimeBrickPrimeBrick

© 2026 PrimeBrick. MIT License. v3.11.2

github
DAL Library
SDK Library
Decimal Library
    Developer Guide
      Getting startedPrecision modelDivision and periodicityRoundingWire formatWhen to useWhen NOT to useExamplesAPI ReferenceContributing
powered by Zudoku
Developer Guide

Wire format

A Decimal must never serialize as a JSON number — that would hand the value to the binary float parser and destroy precision at the boundary. The library provides three explicit serializations:

FunctionOutputUse
toPG(d)"12.34" (plain string)PostgreSQL numeric parameters — the DAL uses this
toWire(d) / toJSON(d)"12.34d" (self-describing)JSON APIs, Ext-JSON — the d suffix marks it for rehydration
toString(d)"12.34"display / logs
toNumber(d)number — lossylast-resort interop only

In JSON

Code
JSON.stringify({ total }); // {"total":"73.47d"} — via toJSON

The d-suffixed string survives JSON.parse untouched and schema-aware hydration (e.g. the SDK Ext-JSON middleware or the DAL hydration path) revives it into a Decimal — precision never crosses a float.

Hydration

  • fromWire("12.34d") — parses the self-describing form (accepts plain "12.34" too)
  • fromPG("12.34") — parses a numeric value as returned by PostgreSQL
  • parseDecimal / dec — general entry point (DecimalInput)

NaN, Infinity, -Infinity (legal numeric values in PG ≥ 14) cannot be represented — fromPG/dec throw DecimalError with code: "NON_FINITE". This is deliberate: a Decimal is always finite.

Last modified on October 28, 2026
RoundingWhen to use
On this page
  • In JSON
  • Hydration
TypeScript