Friday, June 03, 2011

Using C# String.Format “{0:p0}” without the leading space before percentage sign

Simplest expresssion is:  

String.Format("{0:0%}", 0.10)

A more elegant solution is:  

Use the NumberFormatInfo.PercentPositivePattern Property:
NumberFormatInfo numberInfo = new NumberFormatInfo();
numberInfo.PercentPositivePattern = 1;
Console.WriteLine(String.Format("{0}", 0.10.ToString("P0",numberInfo)));


dhasharath said...

interesting blog. It would be great if you can provide more details about it. Thanks you

Web Solutions Company

DigiClayInfotech said...

Great discussion.Thanks for creating a wonderful site.
Web Solution

Young Decade said...

Nice post, it's good to see the difficulty of getting started being recognized. Nice work!
Mobile App Development Company Indore