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.



 Live Demo

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));


97.57 %
97.6 %
97.5746 %
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know