Hello!
I am trying to change output of this to be 2 dec places: dir c:\ -Recurse -File | sort-object -property length | select name, @{Name='Length (GB)';Expression={$_.Length / 1GB}} -last 10
I have tried inserting '{0:F2}' -f before the {$_.Length / 1GB}
But thats not working
I was thinking of using [Math]::round somehow…
Im still learning, can someone show me how to change that calculated property?
Depending on what you actually want you can do both … while the format way might end up in unprecise results it probably will be precise enough in most cases I think. So its a matter of personal preference or taste wich one you use. Another side effect using the format way is that the results become strings. If you want to use the results later on for some calculation you should go with the proper [Math] way.
Using a GB unit might cause all small files displayed as 0.00 in length.
Regardless of that - using aliasses in scripts or in forums is considered very bad style. Please avoid using them.
And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Hi Olaf,
I was dissecting your words and am slightly confused. You say:
Another side effect using the format way is that the results become strings. If you want to use the results later on for some calculation you should go with the proper [Math] way.
In the code, the Math way is labeled formatted.
Is the one that uses {0:F2} the one that becomes a string?