Hello,
I try to export a large decimal number someting like below.
Workbook wb =//Load some workbook here
Worksheet ws1 =//Select a sheet here
ws1.Rows[3].Cells[1].Value = 12312312312.123546789012345679M;
ws1.Rows[3].Cells[1].CellFormat.FormatString ="#########0.000000000000000000000000000000";
//save workbook
When I check the Excel file, it shows "12312312312.1235" only. I tried the formatting option provided with excel (Right click => Format Cells => number format) but no use. When I debug, I could see value with full precision is stored in the Value property of the Cell.
Could anyone pls help me on this?
Thanks,Ganesh
Thanks for the reply
regs,
Ganesh
Microsoft Excel only stores numbers as IEEE 64-bit double-precision floating-point numbers (the same as the Double data type in .NET). The Decimal data type in .NET stores a lot more precision than Double. A Double has 52 bits of precision, which is about 15 decimal digits (notice how the number you are seeing in MS Excel gets cut off after the 15th decimal digit), whereas a Decimal has 96 bits of precision, which is about 28 decimal digits. If you store a Decimal number on a cell, we will maintain that value for you at run-time so that if you ask for it back again, it will not have any precision lost, but when you save the file to one of the Excel file formats, we have no choice but to convert the number to Double so we can save it, thus losing 44 bits of precision. You can verify that this amount of precision is not supported in MS Excel by setting your format string as a custom format on a cell, then entering this number into that cell. When you do, it displays the following text: "12312312312.123500000000000000000000000000"