
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 %
- Related Articles
- C# Currency ("C") Format Specifier
- C# Exponential (“E”) Format Specifier
- C# Numeric (“N”) Format Specifier
- C# Decimal ("D") Format Specifier
- C# Hexadecimal ("X") Format Specifier
- C# Fixed-Point (“F”) Format Specifier
- Sortable ("s") Format Specifier in C#
- C# Round-trip ("R") Format Specifier
- Month ("M", "m") Format Specifier in C#
- Short Time ("t") Format Specifier in C#
- Long Time ("T") Format Specifier in C#
- Year Month ("Y") Format Specifier in C#
- Long Date ("D") Format Specifier in C#
- The "0" custom format specifier in C#
- C# General Date Short Time ("g") Format Specifier

Advertisements