Monday, 31 October 2011

Show-CurrencyGroupSize

  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 tot: 
  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

No comments: