String Formatting in C# using %

CsharpProgrammingServer Side Programming

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%
raja
Published on 31-Aug-2018 13:15:02
Advertisements