Show
Using System;
Class Program
{
static void Main ()
{
Decimal thedecnumber = 12345.678m; The "M" creates a literal of type decimal from a double
Using the ToString method
The number in the format string is the precision specifier
Console.WriteLine ("No formatting:" + thedecnumber.tostring ());
Console.WriteLine ("Currency formatting:" + thedecnumber.tostring ("C"));
Console.WriteLine ("Exponential formatting:" + thedecnumber.tostring ("E"));
Console.WriteLine ("Fixed-point formatting:" + thedecnumber.tostring ("F2"));
Console.WriteLine ("General formatting:" + thedecnumber.tostring ("G"));
Console.WriteLine ("Number formatting to 2 decimal places:" + thedecnumber.tostring ("N2"));
Console.WriteLine ("Number formatting to 3 decimal places:" + thedecnumber.tostring ("N3"));
Console.WriteLine ("Number formatting to 4 decimal places:" + thedecnumber.tostring ("N4"));
Console.WriteLine ("Percent formatting:" + thedecnumber.tostring ("P0"));
int theintnumber = 123456;
Console.WriteLine ("Hexidecimal formatting (for integers): {0} = {1}", Theintnumber, Theintnumber.tostring ("X"));
Double thedblnumber = 1234567890;
Console.WriteLine ("Custom formatting: {0} to US telephone {1}", Thedblnumber, Thedblnumber.tostring ("(###) ###-#"));
Keep Console Open if not run through command prompt
Console.Write ("\npress Enter to Continue");
Console.ReadLine ();
}
}