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.    } 

Thursday 20 June 2013

Show-CurrencyGroupSize.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script reimplements a code sample from MSDN in PowerShell. 
  4.     This sample formats and display currency using standard and 
  5.     different currency groupings.  
  6. .DESCRIPTION 
  7.     This script displays a currency using standard, then two 
  8.     custom CurrencyGroupSizes. 
  9. .NOTES 
  10.     File Name  : Show-CurrencyGroupSize.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN sample posted to: 
  17.         http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencygroupsizes.aspx 
  18. .EXAMPLE 
  19.     PSH:> .\Show-CurrencyGroupSize.ps1 
  20.     Default numeric format string "C" 
  21.     $123,456,789,012,345.00 
  22.  
  23.     Display with array = 2,3,4 
  24.     $12,3456,7890,123,45.00 
  25.  
  26.     Display with array = 2,3,0 
  27.     $1234567890,123,45.00 
  28. #> 
  29.  
  30. #     Get a NumberFormatInfo associated with the en-US culture. 
  31. $fi = new-object System.Globalization.CultureInfo "en-US", false 
  32. $nfi = $fi.NumberFormat 
  33.  
  34. #     Display a value with the default separator (".") 
  35. "Default numeric format string `"C`"" 
  36. [Int64] $myInt = 123456789012345 
  37. $myInt.ToString( "C", $nfi
  38.  
  39. #    Display the same value with different groupings. 
  40. [int[]] $mySizes1 = (2,3,4) 
  41. $mySizes = 2,3,0 
  42.  
  43. "";"Display with array = 2,3,4" 
  44. $nfi.CurrencyGroupSizes = $mySizes1 
  45. $myInt.ToString( "C", $nfi
  46.  
  47. "";"Display with array = 2,3,0" 
  48. $nfi.CurrencyGroupSizes = $mySizes2 
  49. $myInt.ToString( "C", $nfi