add commas using String.Format for number and

后端 未结 7 1087
执笔经年
执笔经年 2020-12-08 07:53

Using String.Format how can i ensure all numbers have commas after every 3 digits eg 23000 = \"23,000\" and that 0 returns \"0\".

String.Format(\"{0:n}\", 0); //give

7条回答
  •  长情又很酷
    2020-12-08 08:20

    You can also play around a little with the CultureInfo object, if none of the other solutions work well for you:

            var x = CultureInfo.CurrentCulture;
            x.NumberFormat.NumberDecimalSeparator = ",";
            x.NumberFormat.NumberDecimalDigits = 0;
            x.NumberFormat.NumberGroupSizes = new int[] {3};
    

提交回复
热议问题