locked
Change number format and convert in MB - GB - TB - PB RRS feed

  • Question

  • Hi guys,

    the result of $RDXtot is a number like 23,50

    the result of $RDXused is a number like 10.50

    so the question is, how can i change format of $RDXused in 10,50 ?

    so with coma ',' and not with the dot '.'

    Other question is: is it possible to convert automatically in TB if the number is bigger than 1000 MB or in MB format if less then 1000 MB ?

    $Using:DriverLetter = 'X:'
    $RDXstorage = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = '$Using:DriverLetter'"
    $RDXtot = "{0:N2}" -f ($RDXstorage.Size/1GB) + " GB"
    $RDXused = ([Math]::Round($RDXstorage.Size/1GB,2)) - ([Math]::Round($RDXstorage.FreeSpace/1GB,2))

    Monday, September 4, 2017 11:51 PM

Answers

  • You would use a script that can use a mathematical formula to get the magnitude of the number. 

    The use of comma or a period is culture dependent. Yu are set to a culture that uses commas.  Change your culture settings to use a culture with the format you want.

    You cannot use math with strings.  Do not add or convert numbers to strings or you will get unpredictable output. Do not use Gb, Mb or other in formulas or you will get the wrong answer.  Just use straight math and convert the required result as needed.


    \_(ツ)_/

    • Proposed as answer by I.T Delinquent Tuesday, September 5, 2017 7:59 AM
    • Marked as answer by Ramses147 Wednesday, September 6, 2017 9:31 PM
    Monday, September 4, 2017 11:57 PM