9

I'm using following code to format decimal number as percentage in excel using Epplus. I have used this example.

sheet.Cells["B:B"].Style.Numberformat.Format = "#0\\.00%";

The number is looking normal in sheets, but in edit bar number is looking different.

The number 9.47% is showing as 947 in edit bar.

Check the image for problem sample. How to resolve this?

enter image description here

Community
  • 1
  • 1
Pandiyan Cool
  • 6,381
  • 8
  • 51
  • 87
  • I don't quite understand the problem. Just set the format to #0.00%. Put 0.0947 on the edit bar and see what you get. – cup May 03 '15 at 10:23
  • 1
    Your code displays `9.47` = `947%` as `9.47%` using some artificial custom formatting trick. If you want to have `9.47%` value in your cell, you should divide it by `100`, and format as `"0%"` – BrakNicku May 03 '15 at 10:25
  • @user3964075 i'm placing decimal value 9.47 in cell, after that i'm formatting with my code. – Pandiyan Cool May 03 '15 at 10:31
  • @cup if we are using this in excel directly its working, but in excel generated by epplus its not working. – Pandiyan Cool May 03 '15 at 10:32
  • 3
    But you can't change cell's value with formatting. `9.47`=`947%` and that's what formula bar will show. If you want it to be `9.47%` you should place `0.0947` in cell and format `"0.00%"` to have percentage with 2 decimal places. – BrakNicku May 03 '15 at 10:34
  • @user3964075 oh ok. then please tell me how to append % symbol alone in cell. – Pandiyan Cool May 03 '15 at 10:35
  • 2
    `"0.00\%"` appends `%`. But formula bar wil still show `9.47` and not `9.47%` – BrakNicku May 03 '15 at 10:41

1 Answers1

8

Short answer: divide the numbers by 100 and use the following custom format 0.00%

Jordan Biserkov
  • 647
  • 6
  • 13