C# – .NET String.Format() to add commas in thousands place for a number cformatnetstring I want to add a comma in the thousands place for a number. String.Format()? Best Answer String.Format("{0:n}", 1234); // Output: 1,234.00 String.Format("{0:n0}", 9876); // No digits after the decimal point. Output: 9,876 Related SolutionsC# – the difference between String and string in C# string is an alias in C# for System.String. So technically, there is no difference. It's like int vs. System.Int32. As far as guidelines, it's generally recommended to use string any time you're referring to an object. e.g. string place = "world"; Likewise, I think it's generally recommended to use String if you need to refer specifically to the class. e.g. string greet = String.Format("Hello {0}!", place); This is the style that Microsoft tends to use in their examples. It appears that the guidance in this area may have changed, as StyleCop now enforces the use of the C# specific aliases. C# – Catch multiple exceptions at once Catch System.Exception and switch on the types catch (Exception ex) { if (ex is FormatException || ex is OverflowException) { WebId = Guid.Empty; return; } throw; } Related TopicC# – What are the correct version numbers for C#Java – How to read / convert an InputStream into a String in JavaJson – How to pretty-print JSON in a shell scriptC# – Case insensitive ‘Contains(string)’Javascript – How to make the first letter of a string uppercase in JavaScriptPython – Does Python have a string ‘contains’ substring methodJava – How to convert a String to an int in Java
Best Answer