GeeksforGeeks App
Open App
Browser
Continue

# C# | Math Class

In C#, Math class comes under the System namespace. It is used to provide static methods and constants for logarithmic, trigonometric, and other useful mathematical functions. It is a static class and inherits the object class.

`public static class Math`

#### Fields

A field is a variable that is declared in a class or struct. These are considered as the members of their containing type. Fields may be static or instance fields. Math class contains the two fields i.e. E and PI.

1. Math.E Field: This field represents the natural logarithmic base, specified by the constant, e.
2. Math.PI Field: It represents the ratio of the circumference of a circle to its diameter, specified by the constant, PI(π).

Example:

 `// C# program to demonstrate the``// value of Math Class Fields``using` `System;`` ` `class` `GFG {`` ` `    ``// Main method``    ``static` `void` `Main()``    ``{`` ` `        ``// To find E constant values``        ``double` `e = Math.E;`` ` `        ``// Print result``        ``Console.WriteLine(``"Math.E = "` `+ e);`` ` `        ``// To find PI constant values``        ``double` `pi_value = Math.PI;`` ` `        ``// Print result``        ``Console.WriteLine(``"Math.PI = "` `+ pi_value);``    ``}``}`

Output:

```Math.E = 2.71828182845905
Math.PI = 3.14159265358979
```

You can read more about fields from C# | Math Class Fields with Examples.

#### Methods

Example:

 `// C# program to illustrate the``// Math class methods``using` `System;`` ` `public` `class` `GFG {`` ` `    ``// Main method``    ``static` `public` `void` `Main()``    ``{`` ` `        ``// using Floor() Method``        ``Console.WriteLine(``"Floor value of 123.123: "``                             ``+ Math.Floor(123.123));`` ` `        ``// using Asin() Method``        ``Console.WriteLine(``"Asin value of 0.35: "``                             ``+ Math.Asin(0.35));`` ` `        ``// using Sqrt() Method``        ``Console.WriteLine(``"Square Root of 81: "``                              ``+ Math.Sqrt(81));`` ` `        ``// using Round() Method``        ``Console.WriteLine(``"Round value of 14.6534: "``                             ``+ Math.Round(14.6534));``    ``}``}`

Output:

```Floor value of 123.123: 123
Asin value of 0.35: 0.35757110364551
Square Root of 81: 9
Round value of 14.6534: 15
```

My Personal Notes arrow_drop_up