Example

using System;

namespace Samples
{
  public class IFormattableSample
  {
    public static void Main()
    {
      double d = 123.12345678901234;
      string[] strings = {"C","E","e","F","G","N","P","R"};
      foreach(string s in strings)
        Console.WriteLine("{0:R} as {1}: {2}",
                          d, s, d.ToString(s,null));
      strings = new string[]{"D","x","X"};
      int i = 255;
      foreach(string s in strings)
        Console.WriteLine("{0} as {1}: {2}",
                          i, s, i.ToString(s,null));
    }
  }
}
The output is
 123.12345678901234 as C: $123.12 123.12345678901234 as c: $123.12 123.12345678901234 as E: 1.231235E+002 123.12345678901234 as e: 1.231235e+002 123.12345678901234 as F: 123.12 123.12345678901234 as G: 123.123456789012 123.12345678901234 as g: 123.123456789012 123.12345678901234 as N: 123.12 123.12345678901234 ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.