Something like this:
var number = "128989899";
Console.WriteLine(String.Format("{0:N0}", Int32.Parse(number)));
Domanda
I have a bunch of data that I get as a string
, and it needs to be formatted as a number (int).
So something like this: 128989899
needs to be displayed as 128,989,899
What would the correct way to achieve this?
PS: Currently existing questions do not address my question, before closing my question, please read it carefully or if you do close it, please provide a concise answer to what I am asking.
Soluzione 2
Something like this:
var number = "128989899";
Console.WriteLine(String.Format("{0:N0}", Int32.Parse(number)));
Altri suggerimenti
If I understand the question correctly, you have a string
containing numbers stored as text.
You wish these to be displayed as comma-separated numbers such as 123,456,789
.
Something along the lines of the following should help to achieve this, simply converting to an int
and then back again into a string in the correct format:
string Input = "128989899";
int TempInt;
int.TryParse(Input, out TempInt);
string Output = TempInt.ToString("#,###");
Duplicate: string format numbers
int number = 1000000000;
string commaseperated = number.ToString("#,##0");