FixedWidthParserWriter icon indicating copy to clipboard operation
FixedWidthParserWriter copied to clipboard

Nullable Decimals Don't Write Correctly with a `0;00` Format

Open joseph-chew opened this issue 9 months ago • 0 comments

When trying to write to a file with a class that has a decimal? property and a format like 0;00 or 0;000, the values to the right of and including the decimal seem to be getting dropped.

Setup for Reproduction (.NET 6)

  1. Create a file that has a number value (one field should do) a) Example: 0000002340
  2. Create a class that has a decimal? property:
public record TestClass
{
    [FixedWidthLineField(Start = 1, Length = 10, Pad = '0', PadSide = PadSide.Left, Format = "0;00")]
    public decimal? TestProperty { get; init; } = default;
}
  1. Read the file into memory, then write the file again.
List<string> readData = File.ReadAllLines(@"PATH_TO_TEST_FILE").ToList();
TestClass testClass = new FixedWidthLinesProvider<TestClass>().Parse(readData).First();

// `testClass.TestProperty` should equal `23.4` after parsing the readData

var writeData = new FixedWidthLinesProvider<TestClass>().Write(new() { testClass });
File.WriteAllLines(@"PATH_TO_NEW_FILE");
  1. Check the newly created file and notice it's 0000000023 instead of the expected 0000002340

joseph-chew avatar Apr 25 '25 03:04 joseph-chew