Visual Basic .NET - Math Functions
Abs Function: Returns the absolute value of a number.
Dim num As Integer = -5
Dim result As Integer = Math.Abs(num)
'Output: 5
Ceiling Function: Returns the smallest integer that is greater than or equal to the specified double-precision floating-point number.
Dim num As Double = 3.14
Dim result As Integer = Math.Ceiling(num)
'Output: 4
Floor Function: Returns the largest integer that is less than or equal to the specified double-precision floating-point number.
Dim num As Double = 3.99
Dim result As Integer = Math.Floor(num)
'Output: 3
Round Function: Rounds a decimal value to the nearest integer or to the specified number of decimal places.
Dim num As Double = 3.14159265358979
Dim result1 As Integer = Math.Round(num)
Dim result2 As Double = Math.Round(num, 2)
'Output1: 3
'Output2: 3.14
Truncate Function: Calculates the integral part of a number and removes the fractional part.
Dim num As Double = 3.99
Dim result As Integer = Math.Truncate(num)
'Output: 3
Sqrt Function: Returns the square root of a specified number.
Dim num As Double = 25
Dim result As Double = Math.Sqrt(num)
'Output: 5
Pow Function: Returns a specified number raised to the specified power.
Dim num1 As Double = 2
Dim num2 As Double = 3
Dim result As Double = Math.Pow(num1, num2)
'Output: 8
Exp Function: Returns the exponential value of a specified number.
Dim num As Double = 3
Dim result As Double = Math.Exp(num)
'Output: 20.0855369231877
Log Function: Returns the natural (base e) logarithm of a specified number.
Dim num As Double = 2.71828182845905
Dim result As Double = Math.Log(num)
'Output: 1
Log10 Function: Returns the base 10 logarithm of a specified number.
Dim num As Double = 100
Dim result As Double = Math.Log10(num)
'Output: 2
Max Function: Returns the larger of two specified numbers.
Dim num1 As Integer = 5
Dim num2 As Integer = 10
Dim result As Integer = Math.Max(num1, num2)
'Output: 10
Min Function: Returns the smaller of two specified numbers.
Dim num1 As Integer = 5
Dim num2 As Integer = 10
Dim result As Integer = Math.Min(num1, num2)
'Output: 5
Sign Function: Returns a value indicating the sign of a number.
Dim num1 As Integer = 5
Dim num2 As Integer = -10
Dim result1 As Integer = Math.Sign(num1)
Dim result2 As Integer = Math.Sign(num2)
'Output1: 1
'Output2: -1
Random Function: Returns a random number between 0.0 and 1.0.
Dim rnd As New Random()
Dim result As Double = rnd.NextDouble()
'Output: random value between 0.0