Powershell Tip Use -f with N0 (Zero)

Use -f with N0
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
Share this tip on: facebook | twitter | linkedin

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s