BR-DEC-02 The allowed maximum number of decimals for the document level allowance base amount (BT-93) is 2, but allowances[0].baseAmount is 100.005, which has 3
The allowed maximum number of decimals for the document level allowance base amount (BT-93) is 2, but allowances[0].baseAmount is 100.005, which has 3. The schematron measures the digits after the decimal point in the serialised XML, so a value that merely *displays* as two decimals still fails when the underlying number carries more. A base amount is normally lifted straight out of a subtotal your own system computed, so it carries whatever precision that computation left behind. It is also the number the percentage is applied to, so an over-precise base tends to produce an over-precise amount alongside it.
This rule is implemented and its error payload below is real, but the long-form write-up — normative text, worked example, divergence note — is not written yet. Everything the library knows about this rule is on this page. Ask and we will prioritise it.
- Business term
BT-93- Severity
fatal
What the library returns
The exact object in result.errors when this rule fires.
Generated by running @attestwire/en16931, not transcribed:
{
"rule": "BR-DEC-02",
"field": "BT-93",
"severity": "fatal",
"message": "The allowed maximum number of decimals for the document level allowance base amount (BT-93) is 2, but allowances[0].baseAmount is 100.005, which has 3. The schematron measures the digits after the decimal point in the serialised XML, so a value that merely *displays* as two decimals still fails when the underlying number carries more. A base amount is normally lifted straight out of a subtotal your own system computed, so it carries whatever precision that computation left behind. It is also the number the percentage is applied to, so an over-precise base tends to produce an over-precise amount alongside it.",
"fix": "Round allowances[0].baseAmount to two decimals before you hand it over — 100.01 here. This package exports round2() for it, which avoids the two JavaScript traps: Math.round(1.005 * 100) / 100 gives 1.00, and (2.675).toFixed(2) gives \"2.67\".",
"example": "\"baseAmount\": 100.01",
"xpath": "/ubl:Invoice/cac:AllowanceCharge[1]/cbc:BaseAmount",
"docsUrl": "https://attestwire.com/rules/BR-DEC-02"
}
xpath locates the element in the generated UBL document,
which is where a KoSIT or Peppol validator will report the same problem.
A passing value
"baseAmount": 100.01The fix
Round allowances[0].baseAmount to two decimals before you hand it over — 100.01 here. This package exports round2() for it, which avoids the two JavaScript traps: Math.round(1.005 * 100) / 100 gives 1.00, and (2.675).toFixed(2) gives "2.67".