reportviewercore icon indicating copy to clipboard operation
reportviewercore copied to clipboard

string format "P" with any any number (ex: P1, P2, P2, etc.) is adding one extra decimal when exported to Excel

Open dandesro71 opened this issue 3 years ago • 3 comments

In most of our reports, we use the the format "P" to format numbers as percentage.

ex: 0.123456 with p gives 12.35%, whenever you export to PDF, Excel, Word, etc.

If you add a number to the format (ex: P1, P2, P3, etc.), the number of decimals matches the number next to P when exported to all document types except Excel. In Excel, there is always one more decimal.

ex: 0.123456 with p1 gives 12.3%, when exported to PDF or Word, but gives 12.35% when exported to Excel 0.123456 with p2 gives 12.34%, when exported to PDF or Word, but gives 12.346% when exported to Excel 0.123456 with p3 gives 12.346%, when exported to PDF or Word, but gives 12.3456% when exported to Excel

I was able tor reproduce the issue in the sample project.

dandesro71 avatar Jul 16 '22 19:07 dandesro71

I can't reproduce the behavior in a sample project. Changing Price column format specifier to P1 produces properly formatted percentage with one decimal digit - both in PDF, XLS and XLSX.

Please provide modified report.rdlc that renders with incorrect number of decimal digits.

lkosson avatar Jul 18 '22 07:07 lkosson

Use a different value (ex: Price = 0.111111m).

The value in the demo ( Price = 1.0499m) doesn't have enough decimals when converted to percentage

dandesro71 avatar Jul 18 '22 16:07 dandesro71

Right - adding decimal places to the Price triggers the behavior. However, the same problem occurs in original Report Viewer when exporting to Excel. It is caused by Microsoft.ReportingServices.Rendering.ExcelRenderer.SPBIF.ExcelCallbacks.Convert.FormatHandler.GetLongNumberFormat, which converts "P1" to "#,##0.0#%", with extra "#" before percent sign.

To keep bug-for-bug compatibility with original Report Viewer, I won't be fixing it in this project. Feel free to fork it and modify the GetLongNumberFormat method as you need.

lkosson avatar Jul 19 '22 04:07 lkosson