Tuesday 6 January 2009

Get-Decimal1.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Demonstrates Decimal arithmetic. 
  4. .DESCRIPTION 
  5.     This script Creates two decimals, then multiplys them and displays them.  
  6. .NOTES 
  7.     File Name  : get-decimal1.ps1 
  8.     Author     : Thomas Lee - tfl@psp.co.uk 
  9.     Requires   : PowerShell V2 CTP3 
  10. .LINK 
  11.     http://www.pshscripts.blogspot.com 
  12.     Posted on msdn: 
  13.     http://msdn.microsoft.com/en-us/library/system.decimal.aspx 
  14. .EXAMPLE 
  15.     PS c:\foo> .\get-decimal1.ps1 
  16.     $d1 is of type: Decimal 
  17.     $d2 is of type: Decimal 
  18.     $d1 (12.1) multiplied by $d2 (12.2) equals: 146.41 
  19.     $d3 is of type: Decimal 
  20. #> 
  21.  
  22. ## 
  23. #  Start of script 
  24. ## 
  25.   
  26. # Create decimal numbers ($d1, $d2) 
  27. [decimal] $d1 = 12.1 
  28. [decimal] $d2 = 12.2 
  29.  
  30. # Create product 
  31. $d3 = $d1*$d1 
  32.  
  33. # print details 
  34. "`$d1 is of type: {0}" -f $d1.gettype().name 
  35. "`$d2 is of type: {0}" -f $d2.gettype().name 
  36. "`$d1 ({0}) multiplied by `$d2 ({1}) equals: {2}" -f $d1,$d2,$d3 
  37. "`$d3 is of type: {0}" -f $d3.gettype().name 
  38. # End of script 

No comments: