C# Math Abs(Decimal)

Description

Math Abs(Decimal) returns the absolute value of a Decimal number.

Syntax

Math.Abs(Decimal) has the following syntax.


public static decimal Abs(
  decimal value
)

Parameters

Math.Abs(Decimal) has the following parameters.

  • value - A number that is greater than or equal to Decimal.MinValue, but less than or equal to Decimal.MaxValue.

Returns

Math.Abs(Decimal) method returns A decimal number, x, such that 0 d x d Decimal.MaxValue.

Example

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


//from   www.j  a va 2s. c o  m
using System;

public class Example
{
   public static void Main()
   {
      decimal[] decimals = { Decimal.MaxValue, 12.45M, 0M, -1.69M, 
                             Decimal.MinValue };
      foreach (decimal value in decimals)
         Console.WriteLine("Abs({0}) = {1}", value, Math.Abs(value));

   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version