Math.Abs Function in VB.NET

How to get the absolute value of a number using VB.NET?

Explanation

Math.Abs Function

Math.Abs() Function in VB.net 2008 is used to return the absolute value of a number.
Syntax:

Math.Abs(number)

In the above syntax Number specifies the number to find the absolute value.
Example:

Module Module1
Sub Main()
Console.WriteLine("Absolute Value of -5 is::
" & Math.Abs(-5))
Console.WriteLine("Absolute Value of 5.5 is::
" & Math.Abs(5.5))
Console.ReadLine()
End Sub
End Module
Result:

Absolute Value of -5 is:: 5
Absolute Value of 5.5 is:: 5.5

In the above example, the absolute value of '-5' is returned as '5' and the decimal value '5.5' returns the same value.

Visual Basic Tutorial


Ask Questions

Ask Question