Tuesday 1 November 2011

Show-CurrencyDecimalSeparator.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements an MSDN script which 
  4.     shows the use of the CurrencyDecimalSeparator 
  5.     property of a numeric format info object.  
  6. .DESCRIPTION 
  7.     This script displays a currency value using  
  8.     the default decimal separator then shows using a 
  9.     custom separator. This is repeated using a German 
  10.     culture.    
  11. .NOTES 
  12.     File Name  : Show-CurrencyDecimalSeparator.ps1 
  13.     Author     : Thomas Lee - tfl@psp.co.uk 
  14.     Requires   : PowerShell Version 2.0 
  15. .LINK 
  16.     This script posted to: 
  17.         http://www.pshscripts.blogspot.com 
  18.     MSDN sample posted to: 
  19.         http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencydecimalseparator.aspx 
  20. .EXAMPLE 
  21.      Psh> .\Show-CurrencyDecimalSeparator.ps1 
  22.     $123,456,789.00 
  23.     $123,456,789 00 
  24.     123.456.789,00 € 
  25.     123.456.789 00 € 
  26. #> 
  27.  
  28. #    Get a NumberFormatInfo associated with the en-US culture 
  29. $nfi = (new-object System.Globalization.CultureInfo "en-US", $false ).NumberFormat 
  30.  
  31. #    Display a value with the default separator ("."). 
  32. $myInt = 123456789 
  33. $myInt.ToString( "C", $nfi )  
  34.  
  35. #    Display the same value with a blank as the separator. 
  36. $nfi.CurrencyDecimalSeparator = " " 
  37. $myInt.ToString( "C", $nfi )  
  38.  
  39. #    Now get a NumberFormatInfo associated with the de-DE culture 
  40. $nfi = (new-object System.Globalization.CultureInfo "de-DE", $false ).NumberFormat 
  41.  
  42. #    Display a value with the default separator (".") 
  43. $myInt = 123456789 
  44. $myInt.ToString( "C", $nfi )  
  45.  
  46. #    Display the same value with a blank as the separator 
  47. $nfi.CurrencyDecimalSeparator = " " 
  48. $myInt.ToString( "C", $nfi )  

No comments: