Skip to content

Instantly share code, notes, and snippets.

@micmaher
Created March 22, 2016 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micmaher/6ee8ba6f39708a9f135e to your computer and use it in GitHub Desktop.
Save micmaher/6ee8ba6f39708a9f135e to your computer and use it in GitHub Desktop.
.NET Framework formatting
$a = 348
"{0:N2}" -f $a # Numeric to 2 decimal places = 348.00
"{0:D8}" -f $a # Decimal 8 places = 00000348
"{0:C2}" -f $a # Currency to two places = €348.00
"{0:P0}" -f $a # Percentage x 100 = 34,800 %
"{0:X0}" -f $a # Hex = 15C
# First number represents the index number of the item to be formatted.
# In this example we take teh second number in the array $a
$a=19385790464, 6786868768
"{1:N0}" -f $a
@micmaher
Copy link
Author

I seen PowerShell MVP Trevor Sullivan use this weird code in a demo and it had me intrigued. I had to find how it worked

"{0:N2}" -f $a

Copy link

ghost commented Mar 22, 2016

yes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment