本文整理匯總了VB.NET中System.Math.Abs方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Math.Abs方法的具體用法?VB.NET Math.Abs怎麽用?VB.NET Math.Abs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Math
的用法示例。
在下文中一共展示了Math.Abs方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
Module Example
Public Sub Main()
Dim decimals() As Decimal = { Decimal.MaxValue, 12.45D, 0D, -19.69D, _
Decimal.MinValue }
For Each value As Decimal In decimals
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Next
End Sub
End Module
輸出:
Abs(79228162514264337593543950335) = 79228162514264337593543950335 Abs(12.45) = 12.45 Abs(0) = 0 Abs(-19.69) = 19.69 Abs(-79228162514264337593543950335) = 79228162514264337593543950335
示例2: Example
Module Example
Public Sub Main()
Dim doubles() As Double = { Double.MaxValue, 16.354e-17, 15.098123, 0, _
-19.069713, -15.058e18, Double.MinValue }
For Each value As Double In doubles
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Next
End Sub
End Module
輸出:
Abs(1.79769313486232E+308) = 1.79769313486232E+308 Abs(1.6354E-16) = 1.6354E-16 Abs(15.098123) = 15.098123 Abs(0) = 0 Abs(-19.069713) = 19.069713 Abs(-1.5058E+19) = 1.5058E+19 Abs(-1.79769313486232E+308) = 1.79769313486232E+308
示例3: Example
Module Example
Public Sub Main()
Dim values() As Short = { Int16.MaxValue, 10328, 0, -1476, Int16.MinValue }
For Each value As Short In values
Try
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Catch e As OverflowException
Console.WriteLine("Unable to calculate the absolute value of {0}.", _
value)
End Try
Next
End Sub
End Module
輸出:
Abs(32767) = 32767 Abs(10328) = 10328 Abs(0) = 0 Abs(-1476) = 1476 Unable to calculate the absolute value of -32768.
示例4: Example
Module Example
Public Sub Main()
Dim values() As Integer = { Int32.MaxValue, 16921, 0, -804128, Int32.MinValue }
For Each value As Integer In values
Try
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Catch e As OverflowException
Console.WriteLine("Unable to calculate the absolute value of {0}.", _
value)
End Try
Next
End Sub
End Module
輸出:
Abs(2147483647) = 2147483647 Abs(16921) = 16921 Abs(0) = 0 Abs(-804128) = 804128 Unable to calculate the absolute value of -2147483648.
示例5: Example
Module Example
Public Sub Main()
Dim values() As Long = { Int64.MaxValue, 109013, 0, -6871982, Int64.MinValue }
For Each value As Long In values
Try
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Catch e As OverflowException
Console.WriteLine("Unable to calculate the absolute value of {0}.", _
value)
End Try
Next
End Sub
End Module
輸出:
Abs(9223372036854775807) = 9223372036854775807 Abs(109013) = 109013 Abs(0) = 0 Abs(-6871982) = 6871982 Unable to calculate the absolute value of -9223372036854775808.
示例6: Example
Module Example
Public Sub Main()
Dim values() As SByte = { SByte.MaxValue, 98, 0, -32, SByte.MinValue }
For Each value As SByte In values
Try
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Catch e As OverflowException
Console.WriteLine("Unable to calculate the absolute value of {0}.", _
value)
End Try
Next
End Sub
End Module
輸出:
Abs(127) = 127 Abs(98) = 98 Abs(0) = 0 Abs(-32) = 32 Unable to calculate the absolute value of -128.
示例7: Example
Module Example
Public Sub Main()
Dim values() As Single = { Single.MaxValue, 16.354e-12, 15.098123, 0, _
-19.069713, -15.058e17, Single.MinValue }
For Each value As Single In values
Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value))
Next
End Sub
End Module
輸出:
Abs(3.402823E+38) = 3.402823E+38 Abs(1.6354E-11) = 1.6354E-11 Abs(15.09812) = 15.09812 Abs(0) = 0 Abs(-19.06971) = 19.06971 Abs(-1.5058E+18) = 1.5058E+18 Abs(-3.402823E+38) = 3.402823E+38