stephanstapel / ZUGFeRD-csharp

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

Decimal places for PriceAmount fixed at 2 digits - need 4 digits e.g. for fuel invoice #398

Open harzmann opened 1 month ago

harzmann commented 1 month ago

PriceAmount is formatted or rounded to 2 decimal places. However, for example, for fuel bills, 4 decimal places are required for the price per liter. Temporary Save function modified: Writer.WriteValue(_formatDecimal(tradeLineItem.GrossUnitPrice.Value,4)); image

stephanstapel commented 1 month ago

Thanks for your suggestion. I'd be more than happy if you could create a PR. I propose to format the decimal with two digits in case the actual value has two or less digits and use four digits only in case they are really set in the decimal value.

This will do it:

Math.Round(tradeLineItem.GrossUnitPrice.Value, 3) != tradeLineItem.GrossUnitPrice.Value

Please add a test case to https://github.com/stephanstapel/ZUGFeRD-csharp/blob/master/ZUGFeRD-Test/XRechnungUBLTests.cs

HolgerPfeifer commented 1 month ago

And the same would be useful for the AllowanceCharge.Amount.

stephanstapel commented 4 weeks ago

@HolgerPfeifer : would you like to contribute?

HolgerPfeifer commented 3 weeks ago

Yes, I would like. It will take me some time to get my devolopment environment ready for GitHub. Currently I only use local BitBucket repositories.

ernie1000 commented 1 day ago

Same problem here. With Version 12.8.0 of the DLL the following lines are written:

    <ram:GrossPriceProductTradePrice>
      <ram:ChargeAmount>24.8600</ram:ChargeAmount>
      <ram:BasisQuantity unitCode="C62">1.0000</ram:BasisQuantity>
    </ram:GrossPriceProductTradePrice>
    <ram:NetPriceProductTradePrice>
      <ram:ChargeAmount>22.3700</ram:ChargeAmount>
      <ram:BasisQuantity unitCode="C62">1.0000</ram:BasisQuantity>
    </ram:NetPriceProductTradePrice>

Both price fields are defined with 4 decimals.

With Version 15.0.0 both fields are filled with 2 decimals even when they come with 4 decimals. I need 4 decimals when a rabate has to be calculated. Please return to the behavior of 12.8.0

stephanstapel commented 1 day ago

Hi @ernie1000 ,

This change was made intentionally and cannot be 'just reversed' as this component is part of lots of applications. I am happy if you send in a pull request to add digits on demand as I suggested above,