string str = DateTime.Now.Month.ToString("00");
MessageBox.Show( "Current month is: " + str ); // 01, 02 ... 11, 12
double tip = 5; // no decimals
MessageBox.Show( "Your tip should be $" + tip.ToString("0.00") ); // $5.00
tip = 5.1; // one decimal
MessageBox.Show( "Your tip should be $" + tip.ToString("0.00") ); // $5.10
tip = 5.135; // three decimals, unrounded -> ToString() method will round!
MessageBox.Show( "Your tip should be $" + tip.ToString("0.00") ); // $5.14
Note - .NET is smart enough not to truncate the integer part to fit your format provider: tip = 123.4; // three digits before decimal point
MessageBox.Show( "Tip should be $" + tip.ToString("0.00") ); // $123.40
double num = 1234.5;
// Separate thousands with a comma (US and Canada)
string northAmStyle = num.ToString("0,000.00");
// Separate thousands with a space (most of Europe)
string euroStyle = num.ToString("0 000.00");
MessageBox.Show( "Here are your pretty numbers:\n" +
northAmStyle +" and "+ euroStyle );