• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

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
0
lrbrister
Asked:
lrbrister
1 Solution
 
RameshSCommented:
Try this


string strNumber = "1234";
        string strFormat = string.Empty;
        if (strNumber.Contains("."))
            strFormat = "#,###.#0";
        else
            strFormat = "#,###";

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

Open in new window

0
 
lrbristerAuthor Commented:
Excellent
Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now