Math.Abs Method (Decimal)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Updated: September 2010

Returns the absolute value of a Decimal number.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared Function Abs ( _
    value As Decimal _
) As Decimal
public static decimal Abs(
    decimal value
)

Parameters

Return Value

Type: System.Decimal
A Decimal, x, such that 0 ≤ x ≤Decimal.MaxValue.

Remarks

The absolute value of a Decimal is its numeric value without its sign. For example, the absolute value of both 1.2 and -1.2 is 1.2.

Examples

The following example uses the Math.Abs(Decimal) method to get the absolute value of several Decimal values.

Dim decimals() As Decimal = {Decimal.MaxValue, 12.45D, 0D, -19.69D, _
                              Decimal.MinValue}
For Each value As Decimal In decimals
   outputBlock.Text += String.Format("Abs({0}) = {1}", value, Math.Abs(value)) & vbCrLf
Next
' The example displays the following output:
'       Abs(79228162514264337593543950335) = 79228162514264337593543950335
'       Abs(12.45) = 12.45
'       Abs(0) = 0
'       Abs(-19.69) = 19.69
'       Abs(-79228162514264337593543950335) = 79228162514264337593543950335
decimal[] decimals = { Decimal.MaxValue, 12.45M, 0M, -19.69M, 
                       Decimal.MinValue };
foreach (decimal value in decimals)
   outputBlock.Text += String.Format("Abs({0}) = {1}", value, Math.Abs(value)) + "\n";

// The example displays the following output:
//       Abs(79228162514264337593543950335) = 79228162514264337593543950335
//       Abs(12.45) = 12.45
//       Abs(0) = 0
//       Abs(-19.69) = 19.69
//       Abs(-79228162514264337593543950335) = 79228162514264337593543950335

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Change History

Date

History

Reason

September 2010

Added a definition of absolute value.

Customer feedback.