PowerTip: Display the Value of Pi to Three Decimal Places

PowerTip: Display the Value of Pi to Three Decimal Places

Rate This
  • Comments 1

Summary: Use Windows PowerShell to display the value of Pi to three decimal places.

Hey, Scripting Guy! Question How can I display the value of Pi to three decimal places by using conditional formatting to avoid rounding numbers up or down?

Hey, Scripting Guy! Answer Use the Fixed-Point (“F”) Format Specifier, and specify the number of desired decimal places. The following technique uses the Windows PowerShell format operator.

PS C:\> "{0:F3}" -f [math]::PI

3.142

 

Leave a Comment
  • Please add 6 and 5 and type the answer here:
  • Post
  • I don't agree with that solution since the question had "avoid rounding numbers up or down".  I'm not sure how you should do it by conditional formating but one (ugly) way is to use this:

    PS C:\> ([math]::truncate(([math]::PI)*1000))/1000

    then you wouldn't get it to round up or down... :)

Page 1 of 1 (1 items)