![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The "%" custom specifier in C#
A % in a format string would multiply a number by 100 before it is formatted.
The percent symbol is added in the number at the location where the % appears.
For an example, declare and initialize a double variable.
double d = .045;
Now, use % custom specifier to multiply number by 100.
d.ToString("#0.##%", CultureInfo.InvariantCulture)
Example
using System; using System.Globalization; class Demo { static void Main() { double d = .045; Console.WriteLine(d.ToString("#0.##%", CultureInfo.InvariantCulture)); Console.WriteLine(String.Format(CultureInfo.InvariantCulture, "{0:#0.##%}", d)); } }
Output
4.5% 4.5%
Advertisements