Reputation: 39612
Using the expression
String.Format("{0:p0}",0.10) gives 10 %
How do I get this to return 10%
(without the space between 10 and %)?
Culture: en-GB
Upvotes: 79
Views: 50974
Reputation: 4866
With a decimal point as well.
String.Format("{0:0.0%}", 0.6493072393590115)
Answer = 64.9%
Upvotes: 4
Reputation: 264
Only enhancing @Jay Riggs response, and because i don´t have enough reputation just to comment, i´d go with:
String.Format(numberInfo, "{0:p0}", 0.10);
I think this way you cover situations where you have to format more than one value:
String.Format(numberInfo, "{0:p0} {1:p0}", 0.10, 0.20);
Upvotes: 7
Reputation: 53593
Use the NumberFormatInfo.PercentPositivePattern Property:
NumberFormatInfo numberInfo = new NumberFormatInfo();
numberInfo.PercentPositivePattern = 1;
Console.WriteLine(String.Format("{0}", 0.10.ToString("P0",numberInfo)));
Upvotes: 37
Reputation: 99
Change the culture info.
For some cultures it displays %10 , % 10 , 10 % , 10% , .1 , .10 , 0.1 , 0.10 ...
I will check which CultureInfo gives you "10%"
Upvotes: 5
Reputation: 50835
If you're OK with not using Format()
you could do 0.10F.ToString("0%");
.
Upvotes: 12