external help file | Module Name | online version | schema |
---|---|---|---|
PSScriptTools-help.xml |
PSScriptTools |
2.0.0 |
Format a numeric value.
Format-Value [-InputObject] <Object> [[-Unit] <String>] [-Decimal <Int32>]
[<CommonParameters>]
Format-Value [-InputObject] <Object> [-Decimal <Int32>] [-AsNumber]
[<CommonParameters>]
Format-Value [-InputObject] <Object> [-Decimal <Int32>] [-Autodetect]
[<CommonParameters>]
Format-Value [-InputObject] <Object> [-AsCurrency] [<CommonParameters>]
This command will format a given numeric value. By default, it will treat the number as an integer. Or you can specify a certain number of decimal places. The command will also allow you to format the value in KB, MB, etc.
You can let the command auto-detect the value and divide with an appropriate value.
PS C:\> Get-CimInstance -class win32_logicaldisk -filter "DriveType=3" |
Select-Object DeviceID,
@{Name="SizeGB";Expression={$_.size | Format-Value -unit GB}},
@{Name="FreeGB";Expression={$_.freespace | Format-Value -unit GB -decimal 2}}
DeviceID SizeGB FreeGB
-------- ------ ------
C: 200 124.97
D: 437 29.01
E: 25 9.67
PS C:\> (Get-Process chrome | measure ws -sum ).sum |
Format-Value -Autodetect -verbose -Decimal 4
VERBOSE: Starting: Format-Value
VERBOSE: Status: Using parameter set Auto
VERBOSE: Status: Formatting 965332992
VERBOSE: Status: Using Autodetect
VERBOSE: ..as MB
VERBOSE: Status: Reformatting 920.61328125
VERBOSE: ..to 4 decimal places
920.6133
VERBOSE: Ending: Format-Value
PS C:\> 3456.5689 | Format-Value -AsCurrency
$3,456.57
Format a value as currency.
PS C:\> 1234567.8973 | Format-Value -AsNumber -Decimal 2
1,234,567.90
Format the value as a number to 2 decimal points.
Type: Object
Parameter Sets: (All)
Aliases:
Required: True
Position: 2
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
The unit of measurement for your value. Valid choices are "KB","MB","GB","TB", and "PB".
If you don't specify a unit, the value will remain as is, although you can still specify the number of decimal places.
Type: String
Parameter Sets: Default
Aliases:
Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
The number of decimal places to return between 0 and 15.
Type: Int32
Parameter Sets: Default, Number, Auto
Aliases:
Required: False
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
Attempt to autodetect and format the value.
Type: SwitchParameter
Parameter Sets: Auto
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Format the numeric value as currency using detected cultural settings. The output will be a string.
Type: SwitchParameter
Parameter Sets: Currency
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
Format the numeric value as a number using detected cultural settings for a separator like a comma. If the incoming value contains decimal points, by default they will be removed unless you use -Decimal.
The output will be a string.
Type: SwitchParameter
Parameter Sets: Number
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/