System.Math

Provides static methods for trigonometric, logarithmic, and other common mathematical functions.

Abs(Double)

Returns the absolute value of a double-precision floating-point number.

Method

Ceiling(Double)

Returns the smallest integral value that is greater than or equal to the specified double-precision floating-point number.

Method

Floor(Double)

Returns the largest integral value that is less than or equal to the specified double-precision floating-point number.

Method

Max(Double, Double)

Returns the larger of two double-precision floating-point numbers.

Method

Min(Double, Double)

Returns the smaller of two double-precision floating-point numbers.

Method

Pow(Double, Double)

Raises a specified number to a specified power.

Method

Round(Double)

Rounds a double-precision floating-point number to the nearest integral value.

Method

Sqrt(Double)

Returns the square root of a specified number.

Method
π

PI

Returns the value of Pi.

Field
e

E

Returns the base of the natural logarithm, e.

Field

Example Usage

// Calculate the hypotenuse of a right triangle
double sideA = Math.Pow(3, double.CreateChecked(2)); // 3^2
double sideB = Math.Pow(4, double.CreateChecked(2)); // 4^2
double hypotenuse = Math.Sqrt(sideA + sideB); // sqrt(9 + 16) = 5

// Get the absolute value
int negativeNumber = -10;
int absoluteNumber = Math.Abs(negativeNumber); // absoluteNumber is 10

// Round a decimal
double valueToRound = 4.7;
double roundedValue = Math.Round(valueToRound); // roundedValue is 5.0