stephanstapel / ZUGFeRD-csharp

C# assembly for creating and reading ZUGFeRD invoices
Apache License 2.0
179 stars 100 forks source link

Wrong output rounding in _formatDecimal in IINvoiceDescriptorWriter.cs #407

Open ChrisOertel opened 17 hours ago

ChrisOertel commented 17 hours ago

Hello, from my point of view the rounding in the function _formatDecimal is not compatible to the FacturX Specs. Specs says that round happens to the next value (Chapter 7.1.8 Rundungsregeln bei Berechnungen):

Für positive Zahlen: Aufrunden auf den nächsthöheren Wert. Beispiel: 13,455 auf zwei Nachkomma-stellen aufgerundet ergibt 13,46.

In the code is the default Rounding used, which ist ToEven and not AwayFromZero.

return Math.Round(value.Value, numDecimals).ToString($"F{numDecimals}", CultureInfo.InvariantCulture);

From the .Net Documentation (https://learn.microsoft.com/en-us/dotnet/api/system.math.round?view=net-8.0#system-math-round(system-decimal-system-int32)): This method uses the default rounding convention of MidpointRounding.ToEven.

Should there be an AwayFromZero in the function?

Regards, Chris

stephanstapel commented 16 hours ago

Rounding is always an issue. Afaik, this should be correct?!

grafik