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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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