Attestwire › Rule reference › BR-DEC-27
BR-DEC-27 A line charge amount may have at most two decimals
noun · EN 16931 · fatal · BT-141
For a sample invoice, the library reports: The allowed maximum number of decimals for the invoice line charge amount (BT-141) is 2, but lines[0].charges[0].amount is 1.005, which has 3.
- Business term
BT-141- Severity
fatal
The fix
Round lines[0].charges[0].amount to two decimals before assigning it (1.00 here). Use half-up rounding away from zero — this package exports round2(), which handles the cases Math.round and toFixed get wrong.
A passing value
"amount": 1.00What the library returns
The full error returned by @attestwire/en16931. It includes the rule ID,
affected field and suggested correction. Developers can use this object in their application:
{
"rule": "BR-DEC-27",
"field": "BT-141",
"severity": "fatal",
"message": "The allowed maximum number of decimals for the invoice line charge amount (BT-141) is 2, but lines[0].charges[0].amount is 1.005, which has 3. The constraint is on the serialised value, so it is about what reaches the XML rather than about what your variable holds — and the line is where over-precision starts, since every document total downstream of it inherits the drift. A line charge is added into the line net amount (BT-131), which must land on two decimals. Per-unit surcharges multiplied by a fractional quantity are the usual source of the extra digits.",
"fix": "Round lines[0].charges[0].amount to two decimals before assigning it (1.00 here). Use half-up rounding away from zero — this package exports round2(), which handles the cases Math.round and toFixed get wrong.",
"example": "\"amount\": 1.00",
"xpath": "/ubl:Invoice/cac:InvoiceLine[1]/cac:AllowanceCharge[2]/cbc:Amount",
"docsUrl": "https://attestwire.com/rules/BR-DEC-27"
}
xpath is always a UBL path. On a CII invoice, look for the
matching CII field instead.