String Formatting in C# using %


Use the String.Fornt to format a string using %.

String.Format format controls in C# also includes percentage (%) This multiplies the value by 100 and appends a percentage sign.

Let’s say our value is −

double val = .322;

Now, use String.Format and format −

string.Format("string = {0:0.0%}", val);

The following is an example −

Example

 Live Demo

using System;

public class Program {
   public static void Main() {
      double val = .322;

      string res = string.Format("string = {0:0.0%}", val);
      Console.WriteLine(res);
   }
}

Output

string = 32.2%

Updated on: 22-Jun-2020

210 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements