Question : Format dbRow

The data below returns a nVarchar as string and may or may not have a decimal and trailing zeros.

Example
2000
2000.25
200.5

I need to format this so that a comma is added and IF there's decimal, then the decimal comes back to 2 decimals

Example
2,000
2,000.25
2,000.50

Answer : Format dbRow

Try this

1:
2:
3:
4:
5:
6:
7:
8:
string strNumber = "1234";
        string strFormat = string.Empty;
        if (strNumber.Contains("."))
            strFormat = "#,###.#0";
        else
            strFormat = "#,###";

        Response.Write("Number = " + Convert.ToDecimal(strNumber).ToString(strFormat));
Random Solutions  
 
programming4us programming4us