Free Support Forum -

Column decimal formatting

I am trying to format a column to two decimal places.

I am using the below code:
Aspose.Cells.Style numeric_style = book1.CreateStyle();
numeric_style.Number = 2;
StyleFlag flg1 = new StyleFlag();
flg1.NumberFormat = true;
sheet1.Cells.Columns[column_index].ApplyStyle(numeric_style, flg1);
book1.Save(filepath, SaveFormat.Xlsx);

But its formatting to 4 decimal places.

Is the right way or is there any other method to do this. Need help with this.

Thanks in advance,


Thanks for your posting and using Aspose.Cells for .NET.

Please download and use the latest version: Aspose.Cells
for .NET v7.3.4.1
. It works fine and displays correct results.

Please see the following test code. I have attached the output xlsx file and the screenshot for your reference.


Workbook workbook = new Workbook();

Worksheet worksheet = workbook.Worksheets[0];

Aspose.Cells.Style numeric_style = workbook.CreateStyle();

numeric_style.Number = 2;

Column ColumnB = worksheet.Cells.Columns[1];

StyleFlag flag = new StyleFlag();

flag.NumberFormat = true;

ColumnB.ApplyStyle(numeric_style, flag);

//Enter some test value in cell B2


workbook.Save(“output.xlsx”, SaveFormat.Xlsx);