Tuesday, October 14, 2008

ToString() Number format

To write a number in a formatted numeric format. Use the 'N' argument in the ToString() method.







int n = 1000;

Console.WriteLine(n.ToString("N"));

// Will produce

1,000.00

// If you don't decimals
Console.WriteLine(n.ToString("N0"));

// Will produce
1,000



No comments:

Post a Comment