Test how your API handles money and decimals

0.1 + 0.2 is 0.30000000000000004 in JavaScript, and in most languages that use binary floating point. An invoicing API that adds line items as floats will be off by a cent sooner or later, and accountants notice cents.

How is money sent?

RepresentationExampleNotes
Integer minor units{"amount": 4200, "currency": "EUR"}Safest. Stripe and many payment APIs use it.
Decimal string{"amount": "42.00", "currency": "EUR"}Exact, but clients must parse it as a decimal, not a float.
JSON number with decimals{"amount": 42.0}Works until it doesn't; clients parse it as a float.

Whatever it is, check it's the same everywhere. A schema assertion on the response pins it:

JSON
{
  "type": "object",
  "required": ["total"],
  "properties": {
    "total": {
      "type": "object",
      "required": ["amount", "currency"],
      "properties": {
        "amount": { "type": "integer" },
        "currency": { "type": "string", "pattern": "^[A-Z]{3}$" }
      }
    }
  }
}

Sums that break floats

Create an invoice with three lines of 33.33 and two lines of 0.10 and 0.20. This API takes decimal strings for unit prices and returns totals in integer cents, as the schema above says:

HTTP
POST {{baseUrl}}/invoices
Content-Type: application/json

{
  "currency": "EUR",
  "lines": [
    {"description": "A", "unitAmount": "33.33", "quantity": 3},
    {"description": "B", "unitAmount": "0.10", "quantity": 1},
    {"description": "C", "unitAmount": "0.20", "quantity": 1}
  ]
}

Check the total exactly, in cents:

JavaScript
const total = pm.response.json().total;
pm.test('total is exact', () => {
  pm.expect(total.amount).to.equal(10029);
  pm.expect(total.currency).to.equal('EUR');
});

If the API adds floats, you get 10028 after truncation, or a schema failure because the amount came back as 100.28999999999999.

Currencies with different decimals

CurrencyMinor units1 major unit is
EUR, USD, PLN2100
JPY, KRW01
KWD, BHD, OMR31000

Code that hard-codes "divide by 100" charges a Japanese customer a hundred times too little. Run one data file across currencies:

CSV
currency,minorAmount,expectedDisplay
EUR,4200,42.00
JPY,4200,4200
KWD,4200,4.200
JavaScript
pm.test(`${pm.iterationData.get('currency')} formatted correctly`, () => {
  pm.expect(pm.response.json().displayAmount).to.include(pm.iterationData.get('expectedDisplay'));
});
Terminal
requestarium run-collection "Billing API" --folder "Currencies" --data currencies.csv --env Staging

Rounding rules

Tax and discounts produce fractions of a cent. 19% VAT on 10.50 is 1.995. Is that 1.99 or 2.00? Rounding half up gives 2.00, and so does rounding half to even (banker's rounding). For 1.985 the two rules disagree: half up gives 1.99, half to even gives 1.98.

Ask the finance team for the rule, then test the half-cent cases explicitly:

JavaScript
pm.test('VAT on 10.50 at 19% rounds to 2.00', () => {
  pm.expect(pm.response.json().taxAmount).to.equal(200);
});

Also check that line-level rounding and total-level rounding agree, or that the invoice says which one it used. Rounding each line and then summing can differ from summing and then rounding by a cent per invoice.

Bad input

  • Negative amounts on a payment endpoint: 400, unless refunds use the same endpoint on purpose.
  • More decimals than the currency has: "42.001" EUR should be rejected, not rounded silently.
  • An unknown currency code: 400, not a default to USD.
  • Very large amounts: 999999999999 should either work or be rejected with a clear limit, not overflow.

See boundary value testing for a data-driven way to send these.