# Mathematical Functions (Math Class) in Visual Basic. Net

Visual Basic. Net (VB.NET) support the use of many different functions. One of this group of functions is the Math Class. Mathematical Functions or Math Class is a group of built-in functions that takes on some prominent math operations.

# Some Math Class functions supported by VB.NET:

- Abs(n)

(n) can take any decimal or double value. This function returns the absolute value of (n). - Cos(n)

(n) can be any decimal or double value (angle). This function returns the cosine of the value (n). - Floor(n)

(n) can be any decimal or double value. This function returns the largest integer less than or equal to the value (n). - Log(n)

(n) can be any decimal or double value. This function returns the natural (base**e**) logarithm of the value (n). - Max(n, m)

Both (n) and (m) can be any decimal or double value. This function returns the larger number between the values (n) and (m). - Min(n, m)

Both (n) and (m) can be any decimal or double value. This function returns the smaller number between the values (n) and (m). - Pow(n, m)

Both (n) and (m) can be any decimal or double value. This function returns the value of (n) raised to the power of (m). - Sin(n)

(n) can be any decimal or double value. This function returns the sine of the value (n). - Sqrt(n)

(n) can be any decimal or double value. This function returns the square root of the value (n). - Tan(n)

(n) can be any decimal or double value. This function returns the tangent of the value (n).

Related: **Select Case Structure in Visual Basic . NET**

**Math Class functions code example:**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub btnAbsValue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbsValue.Click Dim n As Double n = InputBox("Please enter your number!") TextBox1.Text = Math.Abs(n) End Sub Private Sub btnMinimum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinimum.Click Dim n1 As Double Dim n2 As Double n1 = InputBox("Enter the first number!") n2 = InputBox("Enter the second number!") TextBox1.Text = Math.Min(n1, n2) End Sub Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click Dim n As Double n = InputBox("Please enter the number!") TextBox1.Text = Math.Log10(n) End Sub Private Sub btnPower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPower.Click Dim n1 As Double Dim n2 As Double n1 = InputBox("Enter the first number!") n2 = InputBox("Enter the second number!") TextBox1.Text = Math.Pow(n1, n2) End Sub Private Sub btnFloor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFloor.Click Dim n As Double n = InputBox("Please enter your number!") TextBox1.Text = Math.Floor(n) End Sub Private Sub btnSquareRoot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSquareRoot.Click Dim n As Double n = InputBox("Please enter your number!") TextBox1.Text = Math.Sqrt(n) End Sub End Class |

**Output:**

Application Window:

Natural logarithm of 100:

Square root of 78:

Related: **Operators in Visual Basic . NET**

# Some further Math Class functions:

- Acos(n)

(n) can take a decimal or double value. This function returns the angle whose cosine is the (n) value. The value of -1 <= n >= 1 - Asin(n)

(n) can take a decimal or double value. This function returns the angle whose sine is the (n) value. The value of -1 <= n >= 1 - Atan(n)

(n) can take a decimal or double value. This function returns the angle whose tangent is the (n) value. - Ceiling(n)

(n) can take any decimal or double value. This function returns the smallest integral value that is greater than or equal to the value of (n). - Log10(n)

(n) can be any decimal or double value. This function returns the base 10 logarithm of the value (n). - Sign(n)

(n) can be any decimal or double value. This function returns the sign of the value (n). - Exp(n)

(n) can be any decimal or double value. This function returns the value of (**e**) raised to the power of (n)

Write your own codes for these functions and let us know if you have any questions. Moreover; post your comments and stay tuned for further tutorials @ www.codejow.com

Pingback: Event and Event Handler in Visual Basic.Net | CodeJow()