Dindar
Dindar

Reputation: 3235

Thousand separator without precision in C#

Simply I'm looking for a way in which to return an integer to thousand separated string format without precisions.

I tried different format specifier but all of them get me 2 digit precisions .

For instances I would like

123456  => "123,456" and not "123,456,00"

or

1234567 => "1,234,567"  

and not "1,234,567.00"

Upvotes: 6

Views: 5041

Answers (2)

Jon Skeet
Jon Skeet

Reputation: 1500155

You can specify a precision of 0 like this when using the standard numeric format of "n":

string text = value.ToString("n0");

Or in composite form:

Console.WriteLine("The number is {0:n0}", value);

Upvotes: 13

Davide Piras
Davide Piras

Reputation: 44605

try this:

int myNumber = 1234567;

var myString = myNumber.ToString("n0");

Upvotes: 6

Related Questions