0

I have this script line:

Get-WmiObject Win32_ComputerSystem | Select-Object  TotalPhysicalMemory, @{Name="GB";Expression={$_.TotalPhysicalMemory/1GB}}

How to round this result 2 separate places after coma. result at the moment is enter image description here

  • 1
    As an aside: The CIM cmdlets (e.g., `Get-CimInstance`) superseded the WMI cmdlets (e.g., `Get-WmiObject`) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell [Core] (version 6 and above), where all future effort will go, doesn't even _have_ them anymore. For more information, see [this answer](https://stackoverflow.com/a/54508009/45375). – mklement0 Dec 05 '20 at 21:39
  • Does this answer your question? [PowerShell Round & Format Float to max 2 decimals?](https://stackoverflow.com/questions/24037021/powershell-round-format-float-to-max-2-decimals) – iRon Dec 06 '20 at 08:17

1 Answers1

2

You can use the format string operator and specify the number of decimal places like this

Get-WmiObject Win32_ComputerSystem |
  Select-Object TotalPhysicalMemory, 
                @{Name="GB";Expression={"{0:n2}" -f ($_.TotalPhysicalMemory/1GB)}}
mklement0
  • 382,024
  • 64
  • 607
  • 775
Doug Maurer
  • 8,090
  • 3
  • 12
  • 13