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 

No comments: