Question

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.

enter image description here

Was it helpful?

Solution

You can use N2

row.AmountCCC.ToString("N2", CultureInfo.InvariantCulture);

The Numeric ("N") Format Specifier

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top