Thousand separator without precision in C #

I'm just looking for a way to return an integer in a thousand split strings without any restrictions.

I tried a different format specifier, but they all got me 2-digit numbers.

For instances, I would like

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

or

 1234567 => "1,234,567" 

not "1,234,567.00"

+6
source share
2 answers

You can specify an accuracy of 0, for example, when using the standard number format in the "n" section:

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

Or in compound form :

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

try the following:

 int myNumber = 1234567; var myString = myNumber.ToString("n0"); 
+6
source

Source: https://habr.com/ru/post/899545/


All Articles