stephanstapel/ZUGFeRD-csharp

X-Rechnung 3.1 UBL for Deutsche Bahn - gross unit price decimals

Closed this issue · 2 comments

broken down from #254, submitted by @goedo

InvoiceDescriptor22Writer.cs, 268

                        //_writeOptionalAmount(Writer, "ram:ChargeAmount", tradeLineItem.GrossUnitPrice, 4); 
                        _writeOptionalAmount(Writer, "ram:ChargeAmount", tradeLineItem.GrossUnitPrice, 2); //roger

rounding rules from EN16931
#131

I enhanced this. (#258 same change)
Even when
image
this refers to the internal calulcation, IMHO, but the put value should be round. So:

                    //_writeOptionalAmount(Writer, "ram:ChargeAmount", tradeLineItem.GrossUnitPrice, 4); //roger
                    _writeOptionalAmount(Writer, "ram:ChargeAmount", tradeLineItem.GrossUnitPrice, 2); //roger

and I changed _writeOptionalAmount:

            //roger
            if (numDecimals == 2)
            {
                value = System.Math.Round(value.Value, 2, MidpointRounding.AwayFromZero); 
            }
            //!roger
            writer.WriteValue(_formatDecimal(value.Value, numDecimals));