Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"

like image 694
Mostafa Avatar asked Oct 18 '11 18:10

Mostafa


2 Answers

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);
like image 173
Jon Skeet Avatar answered Nov 09 '22 05:11

Jon Skeet


try this:

int myNumber = 1234567;

var myString = myNumber.ToString("n0");
like image 36
Davide Piras Avatar answered Nov 09 '22 03:11

Davide Piras