Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Percentage in StringFormat

I have a technical problem with using percentage in StringFormat method.

The result of String.Format("{0:P}", 0.8526) is 85.26%

but I think it should be 0.8526%

Is it correct ? If yes , How can I get 0.8526% ?

like image 295
Mironline Avatar asked Mar 17 '12 15:03

Mironline


People also ask

How do you write a percentage in string format?

You can do this by using %% in the printf statement. For example, you can write printf(“10%%”) to have the output appear as 10% on the screen.

What is percentage used for in C#?

CSharp Online Training The percent ("P") format specifier is used to multiply a number by 100. It converts the number into a string representing a % (percentage). In the same way, using (“P1”), would only include a single vale after decimal-point.

How do you represent a percentage in python?

Use str.format() with "{:. 0%}" as str to format the number as a percentage. To include a specific number of decimal places, use "{:. n%}" , where n is the desired number of decimal places.

How do you write percentages in a string in python?

The %s signifies that you want to add string value into the string, it is also used to format numbers in a string. After writing the above code (what does %s mean in python), Ones you will print ” string “ then the output will appear as a “ Variable as string = 20 ”.


1 Answers

Console.WriteLine(string.Format("{0}%", 0.8526));

like image 56
Pandor Cai Avatar answered Oct 19 '22 17:10

Pandor Cai