Class EinvoiceDecimal() Professional
Exact fixed-point decimal for amounts, quantities and rates.
The EinvoiceDecimal class implements the exact decimal number type used for all amounts, quantities, prices and percentages which the e-invoice classes calculate or return. The business rules of EN 16931, for example BR-CO-10, BR-CO-13, BR-CO-15 and BR-CO-17, require sums to match exactly to the cent. The numeric type of Xbase++ is an IEEE 754 double precision floating point number, which cannot represent most decimal fractions exactly. The EinvoiceDecimal class avoids this problem by storing the value as an integer scaled by 10^8, which provides 8 decimal digits of internal precision.
An EinvoiceDecimal object is normally created via EinvoiceDecimal():of(). All setter methods of the e-invoice classes which accept an amount, a quantity, a price or a rate, for example EinvoiceLineItem():setPrice() and EinvoicePaymentTerms():addSkonto(), accept a numeric value or a character string and convert it automatically via EinvoiceDecimal():of(). The corresponding getter methods, and all amounts contained in the invoice model returned by AbstractEinvoice():toModel(), for example Totals:GrandTotal or the members :Basis and :Tax of a VAT breakdown group, return an EinvoiceDecimal object instead of a numeric value.
The value of an EinvoiceDecimal object is never changed after the object has been created. The arithmetic methods :add(), :sub(), :mul(), :div(), :neg(), :abs() and :round() return a new EinvoiceDecimal object with the result and leave the original object unchanged.
The methods :toFixed( <nDp> ) and :toPlain( <nMinDp>, <nMaxDp> ) convert the value to a character string, and :toNumber() converts it to a numeric value. The methods :cmp(), :eq(), :isZero() and :isNegative() compare values.
Note: the Xbase++ arithmetic operators cannot be used with EinvoiceDecimal objects. Use the arithmetic methods of the class instead.
LOCAL oModel
oModel := oInvoice:toModel()
? "Grand total:", oModel:Totals:GrandTotal:toFixed(2), oModel:Currency
LOCAL oPrice, oTotal
oPrice := EinvoiceDecimal():of( "19.99" )
oTotal := oPrice:mul( EinvoiceDecimal():of( 3 ) ):round(2)
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.