문제

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

도움이 되었습니까?

해결책

You can use N2

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

The Numeric ("N") Format Specifier

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top