How to display a number as a percent in .NET ?

 Posted by Bharathi Cherukuri on 8/27/2012 | Category: ASP.NET Interview questions | Views: 2795 | Points: 40
Answer:

A number with any type i.e., it might be int or double or decimal, it may be displayed as a percent(%) during the output.
It can be displayed likewise as setting the format type value in the ToString() method as shown in the below example.
Example:

decimal dec = 123.554466;
string s = dec.ToString("P2");


Output:

123.55%


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response