這個範例使用 Math 類別的 Abs 方法來計算數字的絕對值。
' Returns 50.3.
Dim MyNumber1 As Double = Math.Abs(50.3)
' Returns 50.3.
Dim MyNumber2 As Double = Math.Abs(-50.3)
這個範例使用 Math 類別的 Atan 方法來計算 pi 的值。
Public Function GetPi() As Double
' Calculate the value of pi.
Return 4.0 * Math.Atan(1.0)
End Function這個範例使用 Math 類別的 Cos 方法來傳回角度的餘弦函數 (Cosine)。
Public Function Sec(ByVal angle As Double) As Double
' Calculate the secant of angle, in radians.
Return 1.0 / Math.Cos(angle)
End Function這個範例使用 Math 類別的 Exp 方法傳回乘冪數的 e。
Public Function Sinh(ByVal angle As Double) As Double
' Calculate hyperbolic sine of an angle, in radians.
Return (Math.Exp(angle) - Math.Exp(-angle)) / 2.0
End Function這個範例使用 Math 類別的 Log 方法來傳回數字的自然對數。
Public Function Asinh(ByVal value As Double) As Double
' Calculate inverse hyperbolic sine, in radians.
Return Math.Log(value + Math.Sqrt(value * value + 1.0))
End Function這個範例使用 Math 類別的 Round 方法來將數字捨入為最接近的整數。
' Returns 3.
Dim MyVar2 As Double = Math.Round(2.8)
這個範例使用 Math 類別的 Sign 方法來決定數字的正負號。
' Returns 1.
Dim MySign1 As Integer = Math.Sign(12)
' Returns -1.
Dim MySign2 As Integer = Math.Sign(-2.4)
' Returns 0.
Dim MySign3 As Integer = Math.Sign(0)
這個範例使用 Math 類別的 Sin 方法來傳回角度的正弦函數 (Sine)。
Public Function Csc(ByVal angle As Double) As Double
' Calculate cosecant of an angle, in radians.
Return 1.0 / Math.Sin(angle)
End Function這個範例使用 Math 類別的 Sqrt 方法來計算數字的平方根。
' Returns 2.
Dim MySqr1 As Double = Math.Sqrt(4)
' Returns 4.79583152331272.
Dim MySqr2 As Double = Math.Sqrt(23)
' Returns 0.
Dim MySqr3 As Double = Math.Sqrt(0)
' Returns NaN (not a number).
Dim MySqr4 As Double = Math.Sqrt(-4)
這個範例使用 Math 類別的 Tan 方法來傳回角度的正切函數 (Tangent)。
Public Function Ctan(ByVal angle As Double) As Double
' Calculate cotangent of an angle, in radians.
Return 1.0 / Math.Tan(angle)
End Function