Insert a dot character in the number of lines

I have int variables, for example:

int money = 1234567890; 

How can I insert a "." into money and make your format as follows:

 1.234.567.890 
+6
source share
4 answers

You can simply do this:

 var text = money.ToString("N0", System.Globalization.CultureInfo.GetCultureInfo("de")); 

Result:

 1.234.567.890 

(I just selected German culture as I knew what they use . For the separator.)

+13
source

You can use NumberFormatInfo.NumberGroupSeparator :

 NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat; nfi.NumberGroupSeparator = "."; Int64 myInt = 1234567890; Console.WriteLine( myInt.ToString( "N", nfi ) ); 

( Link to ideon. )

+7
source

To get exactly the format, use

 int money = 1234567890; money.ToString(@"#\.###\.###\.##0"); 

Read more about custom formats here . You need to avoid the period, because otherwise the first will be interpreted as decimal. A 0 at the end is necessary if you want to display it for null values.

+4
source

If you want the Money format to try:

  int money = 1234567890; string moneyString = String.Format("{0:C}", money); 

returns "$ 1,234,567,890.00"

I'm not sure what the money format is using. instead of "," but it could just be globalization.

+1
source

All Articles