Paparazzi Paparazzi - 1 year ago 117
C# Question

Int custom ToString

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

Comma every two digits.

Is there a way to do this?


Is a comma every three digits

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download