0

I need to format a decimal field in a .csv file that I write with the LINQtoCSV library of this format: 95.43000000 for that format 95.43. I map this field like this:

[CsvColumn(Name = "Price", OutputFormat = "C")]
public decimal? Price { get; set; }

which gives me a monetary value $95.43. I load the data so that it is brought up to the 6th decimal place, but I need to eliminate strings of zeros at the end:

Price = Math.Round(AdjustPrice(x.Price, x.Ticker), 6)

Anyone can help?

Costa.Gustavo
  • 849
  • 10
  • 21
  • The c format is currency with two decimal places. Change the c format according to following : https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings – jdweng Oct 21 '20 at 13:51
  • "of this format: ... for that format" - what does this mean? – NetMage Oct 21 '20 at 20:00
  • Instead of using the `C` currency formatter, instead use the `F2` fixed point format for your desired output. You can test it like so: `Console.WriteLine($"{price:F2}");`. So in your code it should look like this: `[CsvColumn(Name = "Price", OutputFormat = "F2")]` – Carlo Bos Oct 22 '20 at 13:09

0 Answers0