Thursday, 16 May 2013

Show-CurrencyDecimalDigits.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script demonstrates the use of the CurrencyDecimalDigits 
  4. .DESCRIPTION 
  5.     This script is a re-write of an MSDN sample, using PowerShell 
  6. .NOTES 
  7.     File Name  : Show-CurrencyDecimalDigits.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.currencydecimaldigits%28v=vs.100%29.aspx 
  15. .EXAMPLE 
  16.     PSH> .\Show-CurrencyDecimalDigits.ps1 
  17.     ($1,234.00) 
  18.     ($1,234.0000) 
  19. #> 
  20.  
  21. # Get Number Format 
  22. $nf  = New-Object System.Globalization.CultureInfo  "en-US", $False  
  23. $nfi = $nf.NumberFormat 
  24.  
  25. # Display a negative value with the default number of decimal digits (2). 
  26. [Int64] $myInt = -1234 
  27. $myInt.ToString( "C", $nfi
  28.  
  29. # Displays the same value with four decimal digits. 
  30. $nfi.CurrencyDecimalDigits = 4 
  31. $myInt.ToString( "C", $nfi