How would I separate thousands with space in C#

后端 未结 6 1481
温柔的废话
温柔的废话 2020-12-08 19:00

Assume I have the following decimal number that I have to format so that every thousand should be separated with a space:

 897.11 to 897.11
 1897.11 to 1 897         


        
6条回答
  •  再見小時候
    2020-12-08 19:25

    Sweden Use thousand separator as Space(" ") and Decimal point separator as Comma(,). We can achieve this in the following way.

    decimal myNumbber = 5878.476M;
    var swedishCulture = new CultureInfo("sv-SE");           
    swedishCulture.NumberFormat.NumberDecimalSeparator = ",";
    swedishCulture.NumberFormat.NumberGroupSeparator = " ";
    var s = myNumbber.ToString("#,###.00", swedishCulture);
    

    Which gives the output

    "5 878,48"
    

提交回复
热议问题