CantonCapDocsExplorer

Exact decimals

Every monetary value in this API is a decimal string. Parsing one as a float silently corrupts it.

Canton token amounts routinely exceed the range IEEE-754 doubles can represent exactly. A price, supply or notional that goes through Number(), parseFloat or JSON deserialisation into a float loses its least significant digits — quietly, with no error.

What that looks like

javascript

const exact = "123456789012345678901234567890.123456789";

new Intl.NumberFormat().format(exact);
// → 123,456,789,012,345,678,901,234,567,890.123456789   all 39 digits

new Intl.NumberFormat().format(Number(exact));
// → 123,456,789,012,345,680,000,000,000,000            destroyed at digit 17

Intl.NumberFormat has accepted exact decimal strings since ES2023, so formatting for display needs no conversion at all.

Arithmetic and sorting

For arithmetic use a decimal library — decimal.js, big.js, Python's decimal.Decimal. For sorting, compare the strings after normalising sign, leading zeros and fraction width; a lexical comparison of padded digits is exact and needs no library.

Nulls are not zeros

A null is never a zero, and the two must not be conflated. Market capitalisation is null for every Canton asset because no reviewed circulating-supply methodology exists; FDV is null when no approved total-supply observation is within the methodology's maximum age. Both are stated absences with causes, and a client that renders them as 0 is publishing something the API did not say.