#PSTip How to add thousands separators to a number

Say you have a number like: 133903155, how quickly can you digest it? It’s much easier to read when it’s formatted as 133,903,155. One way to convert the number to a readable string is using the -f Format operator:

PS> $number = 133903155
PS> '{0:N}' -f $number

Print the number without precision digits.

PS> '{0:N0}' -f $number

Under the hood PowerShell is utilizing the String.Format method to format the number (see also Composite Formatting).

PS> [string]::Format('{0:N0}',$number)

Another way to format numbers would be by using an object’s ToString() method.

PS> $number.ToString('N0')

Note that the symbol that separates groups of integers is determined by the current culture used on your system (session):

PS> (Get-Culture).NumberFormat.NumberGroupSeparator
comments powered by Disqus