jehugaleahsa / FlatFiles

Reads and writes CSV, fixed-length and other flat file formats with a focus on schema definition, configuration and speed.
The Unlicense
357 stars 64 forks source link

Decimal format without decimal points #47

Closed hbdbim closed 5 years ago

hbdbim commented 5 years ago

Summary:

Format a decimal field without decimal points.

Ex.: Flat file: 000000000000001999 Decimal: 19.99

pbolduc commented 5 years ago

I would suggest you add some unit testings to validate results. The comment on DecimalPlaces says it will remove decimal places. It is not really what that field is doing. It is acting more like a scale parameter like in SQL columns - decimal(precision, scale). Also, if someone logically would set DecimalPlaces = 0 thinking they dont want decimal places, this code will throw System.DivideByZeroException

I am wondering it would be better to use some kind of transform before parse/format.

jehugaleahsa commented 5 years ago

I am pushing out a 4.4.0 release. I am going to eventually retire the IColumnDefinition.Preprocessor property. I have created 4 new lambda properties called OnParsing, OnParsed, OnFormatting and OnFormatted that get called before and after parsing and formatting values.

I am also adding support for setting an IFormatProvider on the options object to override the culture settings globally rather than needing to do it on each column individually.

You'll have to let me know whether the new delegate properties give you the flexibility you need.