Reputation: 10345
I have amounts with decimals (300.11 and 9801.98), I export them Excel and everything is fine.
But sometimes I have amounts with trailing zeros, and I want to keep those zeros when exporting? For example 300.00 becomes 300 when exporting to Excel. How can I fix this?
This is the code right before the export happens.
AmountCCC is of type double.
row.Amount = row.AmountCCC.ToString(CultureInfo.InvariantCulture);
See in the screenshot how the records are exported.
Upvotes: 2
Views: 1871
Reputation: 460208
You can use N2
row.AmountCCC.ToString("N2", CultureInfo.InvariantCulture);
The Numeric ("N") Format Specifier
Upvotes: 2