indice-co / EDI.Net

EDI Serializer/Deserializer. Supports EDIFact, X12 and TRADACOMS formats
MIT License
447 stars 170 forks source link

Picture with implicit V9 on decimal? still adds a decimal separator #255

Closed solexsylvain closed 6 months ago

solexsylvain commented 6 months ago

With the following class

        [EdiSegment]
        public class SAC
        {

            [EdiValue(Path = "SAC/0", Description = "SAC01 - Reference identification qualifier")]
            public string Indicator { get; set; }

            [EdiValue(Path = "SAC/1", Description = "SAC02 - Service, Promotion, Allowance or Charge Code")]
            public string Code { get; set; }

            [EdiValue("9(13)V9(2)", Path = "SAC/4", Description = "SAC05 - Amount")]
            public decimal? Amount { get; set; }

            [EdiValue(Path = "SAC/7", Description = "SAC08 - Allowance or charge rate per unit")]
            public decimal? ACRate { get; set; }

            [EdiValue(Path = "SAC/14", Description = "SAC15 - Description")]
            public string Description { get; set; }
        }

When the file is generated I end up with 0000000000015.25 instead of 000000000001525 for the Amount. The implicit doesn't remove the decimal separator. Am I missing something ?

cleftheris commented 6 months ago

You need to set the Advice in your grammar to not have any separator for decimal mark. That makes it omitted when writing. Otherwise the format is only accounted for precision. It is the 7th argument on the set advice method.

            grammar.SetAdvice('+', '+', ':', '\'', '?', null, null);
solexsylvain commented 6 months ago

In the same EDI file, you could have 2 properties, one that needs output in N2 and the other in R. Won't it break for the R while making it work for the N2 if we set it with the grammar ?

cleftheris commented 6 months ago

You are correct. If this is an exception case then you are probably better off making the exception Value a sting instead of a decimal. Then handle the conversion when populating.

Alternatively make the Amount an int and pad it with multiplication: Amount = (int)(myAmountDecimal * 100)

solexsylvain commented 6 months ago

I was surprised to get an answer so fast. I had changed the property to string before creating the issue since I didn't know when I would get a reply. Thank you for the help.