Paparazzi Paparazzi - 7 days ago 4
C# Question

Int custom ToString

I would like to print out UInt32 as ##,##,##.

Comma every two digits.

Is there a way to do this?

ToString("N0");


Is a comma every three digits

Answer

You should be able to use (with using System.Globalization;):

yourUInt.ToString("N0", new NumberFormatInfo { NumberGroupSizes = new[] { 2, }, })

Documentation: NumberGroupSizes property


Of course, this NumberGroupSizes property can also be set on the NumberFormat property of a CultureInfo (possibly obtained by cloning an existing read-only CultureInfo) which can then be assigned to System.Threading.Thread.CurrentThread.CurrentCulture.