PowerTip: Use PowerShell to Display Number Grouping and Control Decimal Places


Summary: Use Windows PowerShell to display number grouping and control the number of displayed decimal places.

Hey, Scripting Guy! Question How can I use Windows PowerShell to group digits and control the number of decimal places in a large number?

Hey, Scripting Guy! Answer Use the Numeric Format Specifier, and specify the number of required decimal places. Here are a few examples:

PS C:\> (1000*1000).tostring("N")

1,000,000.00

PS C:\> (1000*1000).tostring("N1")

1,000,000.0

PS C:\> (1000*1000).tostring("N3")

1,000,000.000

Comments (2)

  1. tommymaynard says:

    If you’re playing along at home, or rather in your console, then use N0 to remove all the decimal places; great PowerTip! Keep in mind that once you use the ToString() method you’re no longer working with a numeric value: (1000*1000).tostring("N") + 5
    become 1,000,000.005 not 1,000,005.00

  2. Well done Ed. You are doing a great job!

Skip to main content