- Trending Categories
- 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
C# Percent ("P") Format Specifier
The percent ("P") format specifier is used to multiply a number by 100.
It converts the number into a string representing a % (percentage).
We have the following double type −
double val = .975746;
If we will set (“P”) format specifier, then the above would result as −
97.57 %
In the same way, using (“P1”), would only include a single vale after decimal-point.
97.6%
Example
using System; using System.Globalization; class Demo { static void Main() { double val = .975746; Console.WriteLine(val.ToString("P", CultureInfo.InvariantCulture)); Console.WriteLine(val.ToString("P1", CultureInfo.InvariantCulture)); Console.WriteLine(val.ToString("P4", CultureInfo.InvariantCulture)); } }
Output
97.57 % 97.6 % 97.5746 %
Advertisements