Skip to Content
SelloDeveloper docs
Guides

Money and decimals

All monetary values are exact-decimal strings, never floats.

Tax math must be exact. A comprobante's totals have to reconcile to the cent, and Hacienda re-computes and re-validates them. Floating-point arithmetic silently loses precision (0.1 + 0.2 !== 0.3), so Sello never uses it for money.

The rule: money is a string

Every monetary value in the API is a JSON string, never a JSON number. They are exact decimals carried as strings and computed with decimal arithmetic end-to-end.

{
  "resumenFactura": {
    "totalVenta": "1000.00",
    "totalImpuesto": "130.00",
    "totalComprobante": "1130.00"
  }
}

Not:

{ "totalComprobante": 1130.0 }

This applies to line amounts, tax amounts, totals, and the Mensaje Receptor credit hints (montoTotalImpuestoAcreditar, montoTotalDeGastoAplicable) — all of them are Decimal strings.

Why strings

  • No precision loss. A string decimal round-trips exactly; a float does not.
  • It matches Hacienda. The signed XML carries fixed-precision decimals; representing them as strings keeps the API, the XML, and Hacienda's re-computed totals byte-consistent.
  • It's the contract. The OpenAPI Decimal type is a string; every generated SDK types these fields as strings, so you can't accidentally pass a float.

Working with money in your app

Do your own arithmetic with a decimal library (not Number), and serialize to a fixed-scale string when you build the request:

import Decimal from 'decimal.js';

const line = new Decimal('1000.00');
const iva = line.times('0.13');           // exact
const total = line.plus(iva);

const resumenFactura = {
  totalVenta: line.toFixed(2),            // "1000.00"
  totalImpuesto: iva.toFixed(2),          // "130.00"
  totalComprobante: total.toFixed(2),     // "1130.00"
};

Never JSON.parse a comprobante into a shape that coerces these fields to numbers, and never build totals with native floating-point. Keep money as strings from your database to the wire.

On this page