Showing posts with label ToString(). Show all posts
Showing posts with label ToString(). Show all posts

Saturday, 12 November 2011

Show-NumberPadding3.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Shows formatting of double values. 
  4. .DESCRIPTION 
  5.     This script, a re-implementation of an MSDN Sample,  
  6.     creates a double value then formats it with 5 leading 
  7.     zeros. 
  8. .NOTES 
  9.     File Name  : Show-NumberPadding3.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://pshscripts.blogspot.com/ 
  15.     MSDN sample posted to: 
  16.         http://msdn.microsoft.com/en-us/library/dd260048.aspx  
  17. .EXAMPLE 
  18.     Psh> Show-NumberPadding3.ps1 
  19.     01053240 
  20.     00103932.52 
  21.     01549230 
  22.  
  23.             01053240 
  24.          00103932.52 
  25.             01549230 
  26.        9034521202.93 
  27.  
  28. #>   
  29.  
  30. $fmt                 = "00000000.##" 
  31. [int]     $intValue  = 1053240 
  32. [decimal] $decValue  = 103932.52 
  33. [float]   $sngValue  = 1549230.10873992 
  34. [double]  $dblValue  = 9034521202.93217412 
  35.  
  36. # Display the numbers using the ToString method 
  37. $intValue.ToString($fmt
  38. $decValue.ToString($fmt
  39. $sngValue.ToString($fmt)            
  40. "" 
  41.  
  42. # Display the numbers using composite formatting 
  43. $formatString = " {0,15:" + $fmt + "}"  # right justified 
  44. $formatString -f $intValue  
  45. $formatString -f $decValue  
  46. $formatString -f $sngValue       
  47. $formatString -f $dblValue 

Monday, 31 October 2011

Show-StandardNFS-1.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script shows the first two samples on this MSDN Page, 
  4.     convered to PowerShell  
  5. .DESCRIPTION 
  6.     This script displays two lines of text using PowerShell 
  7.     and .NET formatting information 
  8. .NOTES 
  9.     File Name  : Show-StandardNFS-1.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15.     MSDN sample posted tot: 
  16.         http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx 
  17. .EXAMPLE 
  18.     [Cookham8:C:\foo]> .\Show-StandardNFS.ps1 
  19.     $123.46 
  20.     Your account balance is $123.46. 
  21. #> 
  22.  
  23. # Show formatting a number as currency 
  24. $value = 123.456 
  25. $value.ToString("C2"
  26.  
  27. # Show the -f operator with currency formatting 
  28. $value = 123.456 
  29. "Your account balance is {0:C2}." -f $value