Search code examples
c#pi

PI decimal using Math.Round


I'm looking for an answer to the following:

Desired behaviour

Round the mathematical constant pi to 2 or 4 decimals.

Current code

I have tried the following:

Double piRounded;
piRounded = Math.Round.PI(4);
piRounded = Math.Round.PI(2);

Current result

This results in the following error:

'System.Math.Round(double)' is a 'method', which is not valid in the given context


Solution

  • Math.Round in your code is being specified as a property, not a method invocation.

    Place your parameters in the round function like Math.Round(...) - You will want to pass in the PI constant.

    Math.Round(Math.PI, 4) (as stated in comments).