Abs Method (Decimal)
Collapse the table of content
Expand the table of content

Math.Abs Method (Decimal)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Returns the absolute value of a Decimal number.

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

public static decimal Abs(
	decimal value
)

Parameters

value
Type: System.Decimal
A number that is greater than or equal to Decimal.MinValue, but less than or equal to Decimal.MaxValue.

Return Value

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

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.

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


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


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft