Mega Code Archive

 
Categories / C# Tutorial / String
 

Use the Format() method to format a string

using System; class MainClass {   public static void Main()   {          float myFloat = 1234.56789f;     string myString8 = String.Format("{0, 10:f3}", myFloat);     Console.WriteLine("String.Format(\"{0, 10:f3}\", myFloat) = " + myString8);   } } String.Format("{0, 10:f3}", myFloat) = 1234.568