0

Possible Duplicate:
.NET String.Format() to add commas in thousands place for a number

Hi Guys,

I have got 26750 in my string variable, something like below:

string str = "26750";

Now before showing on page, I want it to be converted into "26,750" format using c#. This value can increase as well as decrease also according to the result, so my format should work in both the cases.

Please suggest!

EDIT:

As I have written I have got string type value in my variable, I am trying with below code, but it is not working for me.

spnMiles.InnerHtml = String.Format("{0:n}", Miles);

It is not changing to the number format.

Please suggest!

Community
  • 1
  • 1
Manoj Singh
  • 7,569
  • 34
  • 119
  • 198

1 Answers1

0

This question should answers yours:

.NET String.Format() to add commas in thousands place for a number

Community
  • 1
  • 1
Thomas
  • 7,933
  • 4
  • 37
  • 45
  • 1
    can I have example code for my problem? – Manoj Singh Feb 14 '11 at 10:23
  • 1
    @MKS if you want to learn to program you shouldn't let people spoon feed you. Try to figure it out first. – Marlon Feb 14 '11 at 21:16
  • The suggested duplicate has a subtle difference and is not quite the question asked because this question asks to format a string that is a number and the duplicate answer formats a numerical value which does not work on a string. The solution is to parse the string as a numeric before formatting. For example: string sTotal = "19032"; int iTotal = 0; int.TryParse(sTotal, out iTotal); string.Format("{0:n0}", iTotal); will give 19,032 as the output. – Chad Miller Apr 06 '16 at 20:47