Tuesday, 7 August 2012

Show-Formatting1.ps1

  1. <#
  2. .SYNOPSIS
  3. MSDN Sample Recoded in PowerShell demonstrating formatting
  4. .DESCRIPTION
  5. This sample recodes an MSDN Sample into PowerShell that
  6. shows some of the options of formatting using ToString() and
  7. various .NET formatting strings
  8. .NOTES
  9. File Name : Show-Formatting1.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 to:
  16. http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
  17. .EXAMPLE
  18. Psh> .\Show-Formatting1.ps1\
  19. 00123
  20. 1.20
  21. 01.20
  22. 01,20
  23. 0.6
  24. 1,234,567,890
  25. 1.234.567.890
  26. 1,234,567,890.1
  27. 1,234.57
  28. #>
  29. ## Start script
  30. [double] $value = 123;
  31. $value.ToString("00000")
  32. # Displays 00123
  33. $value = 1.2;
  34. $value.ToString("0.00", [System.Globalization.CultureInfo]::InvariantCulture)
  35. # Displays 1.20
  36. $value.ToString("00.00",[System.Globalization.CultureInfo]::InvariantCulture)
  37. # Displays 01.20
  38. $value.ToString("00.00",
  39. [System.Globalization.CultureInfo]::CreateSpecificCulture("da-DK"))
  40. # Displays 01,20
  41. $value = .56
  42. $value.ToString("0.0", [System.Globalization.CultureInfo]::InvariantCulture)
  43. # Displays 0.6
  44. $value = 1234567890
  45. $value.ToString("0,0", [System.Globalization.CultureInfo]::InvariantCulture)
  46. # Displays 1,234,567,890
  47. $value.ToString("0,0",
  48. [System.Globalization.CultureInfo]::CreateSpecificCulture("el-GR"))
  49. # Displays 1.234.567.890
  50. $value = 1234567890.123456;
  51. $value.ToString("0,0.0", [System.Globalization.CultureInfo]::InvariantCulture)
  52. # Displays 1,234,567,890.1
  53. $value = 1234.567890;
  54. $value.ToString("0,0.00", [System.Globalization.CultureInfo]::InvariantCulture)
  55. # Displays 1,234.57

No comments: