Alex Rivera | Logout

How to format a number as percentage without the percentage sign?

Asked 2009-06-02T12:00:26.810
24

How do I in .NET format a number as percentage without showing the percentage sign?

If I have the number 0.13 and use the format string {0:P0} the output is 13 %.

However I would like to get 13 instead, without having to multiply the number by 100 and using the format string {0:N0}.

(Background: In ASP.NET I have a GridView with a BoundField where I would like to display a number as percentage but without the percentage sign (%). How do I do that?)


Thanks for the answers. At the time of editing 4 out of 6 suggest what I would like to avoid, as explained above. I was looking for a way to use a format string only, and avoid multiplying by 100 and using {0:N0}, but the answers indicate that's impossible...

Edit
Report

2 Answers

15

Why don't you just multiply the number by 100 and use your "{0:N0}" format string? That seems to me to be the easiest solution.

Unless you can come up with a viable reason why that's out of the question, that's my advice. It's not rocket science :-)

answered 2009-06-02T12:03:47.257
0

How about a trim?

double d = .102;
string percent = d.ToString("P0").Trim(' ', '%');
answered 2009-06-02T12:10:58.940

Your Answer