Friday, 28 June 2013

Show-CurrencyFormatting.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements an MSDN Sample showing the  
  4.     use of the NumberFormat class to nicely format things 
  5.     in this case, currency. 
  6. .DESCRIPTION 
  7.     This script iterates through the Windows cultures and 
  8.     displays those whose 2-letter ISO code is 'en' and  
  9.     displays how Windows formats currency in that culture.  
  10. .NOTES 
  11.     File Name  : Show-CurrencyFormatting.ps1 
  12.     Author     : Thomas Lee - tfl@psp.co.uk 
  13.     Requires   : PowerShell Version 2.0 
  14. .LINK 
  15.     This script posted to: 
  16.         http://www.pshscripts.blogspot.com 
  17.     MSDN sample posted to: 
  18.         http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.aspx 
  19. .EXAMPLE 
  20.     Psh > .\Show-CurrencyFormatting.ps1 
  21.     The currency symbol for 'English (United States)' is '$' 
  22.     The currency symbol for 'English (United Kingdom)' is '£' 
  23.     The currency symbol for 'English (Australia)' is '$' 
  24.     The currency symbol for 'English (Canada)' is '$' 
  25.     The currency symbol for 'English (New Zealand)' is '$' 
  26.     The currency symbol for 'English (Ireland)' is '€' 
  27.     The currency symbol for 'English (South Africa)' is 'R' 
  28.     The currency symbol for 'English (Jamaica)' is 'J$' 
  29.     The currency symbol for 'English (Caribbean)' is '$' 
  30.     The currency symbol for 'English (Belize)' is 'BZ$' 
  31.     The currency symbol for 'English (Trinidad and Tobago)' is 'TT$' 
  32.     The currency symbol for 'English (Zimbabwe)' is 'Z$' 
  33.     The currency symbol for 'English (Republic of the Philippines)' is 'Php' 
  34.     The currency symbol for 'English (Singapore)' is '$' 
  35.     The currency symbol for 'English (Malaysia)' is 'RM' 
  36.     The currency symbol for 'English (India)' is 'Rs.' 
  37.  
  38. #> 
  39.  
  40. #  Loop through all the specific cultures known to the CLR. 
  41. foreach ($ci in [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::SpecificCultures))  
  42.    { 
  43.      # Only show the currency symbols for cultures that speak English. 
  44.      if ($ci.TwoLetterISOLanguageName -eq "en") { 
  45.      # Display the culture name and currency symbol. 
  46.         $nfi = $ci.NumberFormat 
  47.         "The currency symbol for '{0}' is '{1}'" -f $ci.DisplayName, $nfi.CurrencySymbol 
  48.      } 
  49.    } 

No comments: