Question: I'm trying to add comma separators to a number. I've tried the advice here: [add commas using String.Format for number and](https://stackoverflow.com/questions/2545633/add-commas-using-string-format-for-number-and) and here: [.NET String.Format() to add commas in thousands place for a number](https://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a-number) but I can't get it to work - they just return the number without commas. The code I'm using is here:

`public static string addCommas(string cash) {
 return string.Format("{0:n0}", cash).ToString();  

 }`

Where am I going wrong?

Thanks.

---

Update: Hi all, thanks for your help, but all of those methods are returning the same error: "error CS1502: The best overloaded method match for 'BishopFlemingFunctions.addCommas(int)' has some invalid arguments" (or variations therof depending on what number type I'm using.) Any ideas?

Answer: 
In order to apply number formatting you have to pass `cash` as a number type (int, double, float etc)
Here is a fairly efficient way to Add commas for thousands place, etc.
It is written in VB.net.
It does not work for negative numbers.

```
Public Function AddCommas(number As Integer) As String
    Dim s As String = number.ToString()
    Dim sb As New StringBuilder(16)
    Dim countHead As Integer = s.Length Mod 3
    If countHead = 0 Then countHead = 3
    sb.Append(s.Substring(0, countHead))

    For I As Integer = countHead To s.Length - 1 Step 3
        sb.Append(","c)
        sb.Append(s.Substring(I, 3))
    Next

    Return sb.ToString()
End Function

```