Use -f with N0

by Dec 21, 2012

Often, it is necessary to output numbers, but you may want to control the number of digits and would like to control the formatting. The -f operator can do this and has a trillion options but there's just one you need to remember: N0 (the "0" is the number zero).

PS> '{0:N0}' -f (8GB/12KB)
699,051

It rounds the number so there are no digits after the decimal, and it adds a separator every three numbers if the number is more than 999. Replace "N0" with "N1" or any other number to control the digits after the decimal:

PS> '{0:N2}' -f (8GB/12KB)
699,050.67

Twitter This Tip! ReTweet this Tip!