Sunday, 28 July 2013

Show-NumberGroupSizes.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates the use of the NumberGroupSizes 
  4. .DESCRIPTION 
  5.     This script is a re-write of an MSDN sample, using PowerShell 
  6. .NOTES 
  7.     File Name  : Show-NumberGroupSizes.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell Version 3.0 
  10. .LINK 
  11.     This script posted to: 
  12.         http://www.pshscripts.blogspot.com 
  13.     MSDN sample posted to: 
  14.          http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.numbergroupsizes%28v=vs.100%29.aspx 
  15. .EXAMPLE 
  16.     PSH> .\Show-NumberGroupSizes.ps1 
  17.     123,456,789,012,345.00 
  18.     12,3456,7890,123,45.00 
  19.     1234567890,123,45.00 
  20. #> 
  21.  
  22. # Get Number Format 
  23. $nf  = New-Object System.Globalization.CultureInfo  "en-US", $False  
  24. $nfi = $nf.NumberFormat 
  25.  
  26. [Int64] $myInt = 123456789012345 
  27. $myInt.ToString( "N", $nfi
  28.  
  29. # Display the same value with different groupings 
  30. [int[]] $MySizes1 = 2,3,4 
  31. [int[]] $MySizes2 = 2,3,0 
  32.  
  33. $nfi.NumberGroupSizes = $mySizes1 
  34. $myInt.ToString( "N",$nfi
  35. $nfi.NumberGroupSizes = $mySizes2 
  36. $myInt.ToString( "N", $nfi )  

No comments: