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.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
- Type: System.Decimal
A number that is greater than or equal to Decimal.MinValue, but less than or equal to 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
Show: