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)));

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

Leave a reply to IICE-Indore Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.