繁体   English   中英

假设 Excel 下载存在十进制数据舍入到 2 位的问题

[英]Aspose Excel downloading having Issue of Rounding off to 2 digits for decimal data

在 Aspose 中,该字段正在四舍五入,即使它在 Excel 本身中获得了正确的十进制数据。 此外,我的代码中没有额外的四舍五入到小数点后两位的公式。

我发现问题是 Aspose 没有提供 3 位十进制数字的 SetPrecision,这就是它被格式化为 2 位数字的原因。 所以而不是property. Number = 2; property. Number = 2; 我使用property.Number = 0; 它得到了解决。 它现在格式化为小数。

https://reference.aspose.com/cells/net/aspose.cells/style/number/#:~:text=2-,Decimal,0.00,-3

要设置 3 个十进制数字,您可以尝试使用 Style.Custom 属性而不是 Style.Number。 事实上,使用 Aspose.Cells 您可以使用建议的属性指定任何或您想要的十进制数字。 有关如何为数字指定 3 个十进制数字的示例代码,请参见以下示例代码:

示例代码:

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Cells["A1"].PutValue(3735.7564);
//Create a style object
Style style = workbook.CreateStyle();
//Set 3 decimal digits precision
style.Custom = "0.000";//also, using "0.0000" will set 4 decimal digits
//Apply the style to the cell
sheet.Cells["A1"].SetStyle(style);
//Save the Excel file
workbook.Save("e:\\test2\\out1.xlsx");

希望这会有所帮助,您也可以在专用论坛中发布查询。

PS。 我在 Aspose 担任支持开发人员/传播者。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM