Free Support Forum - aspose.com

Format Percentage with number of decimal before 0

Hi,

Currently, I am using Aspose cell Net 20.5 version

I want to format the cell in percentage to the positive decimal values triimming 0

I have decimal value rounded to 4 digit.

If number is

10.0000 - 10%
10.1000 - 10.1%
10.1100 - 10.11%
10.1110 - 10.111%
10.1111 - 10.1111%

Do I need to set up individually for each cell or I can set up for the whole column,
As of now, I am doing for whole column custom => style.Custom = “0.0000%”; which is formatting all to 4 decimal.

can any help me with this

@pankajgrwl123,

Please try using the following custom formatting string:
e.g.
Sample code:

style.Custom = "#.####%";

Hope, this helps a bit.

Its printing like this

24.%
20.6667%
17.3333%
.%
14.%
10.6667%
13.3333%

@pankajgrwl123,

Yes, there is one exception. i.e., if there is no decimal part with the value, with this pattern/string, the decimal point will always exist and you cannot remove it. This is same as MS Excel as you may check it in MS Excel manually. So, for those extra decimal point, you got to handle it accordingly by yourselves.

Is there any other way i can achieve rather then setting for each cell individually

@pankajgrwl123,

You may create/specify the Style object with suggested custom formatting ("#.####%") and then create StyleFlag object with relevant formatting attribute on. Now you may apply that style to the whole column, row or your desired range using Column.ApplyStyle or Range.ApplyStyle method accordingly. This way, you will set the custom formatting to the whole column or range of cells in one go (instead of browsing each cell and get/set the style individually).

Hope, this helps a bit.