Home  |  Delphi .net Home  |  System.Math  |  Abs Method
Abs  
Method  
Gets the absolute value of a number
Math Class
System NameSpace
CF1.  Function Abs ( Value : SByte; ) : Sbyte;
CF2.  Function Abs ( Value : SmallInt; ) : SmallInt;
CF3.  Function Abs ( Value : ShortInt; ) : ShortInt;
CF4.  Function Abs ( Value : Integer; ) : Integer;
CF5.  Function Abs ( Value : Int64; ) : Int64;
CF6.  Function Abs ( Value : Single; ) : Single;
CF7.  Function Abs ( Value : Double; ) : Double; Static;
CF : Methods with this mark are Compact Framework Compatible
Description
Returns the absolute value of the number.
Notes
The Delphi IDE at the time of writing does not display SByte in the popup list of Abs syntaxes.

Static methods are not methods of an object - they are simply class functions or procedures available at any time.
Microsoft MSDN Links
System
System.Math
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  float, bigFloat : Single;
  int             : Integer;

begin
  float    := -1.5;       // Small negative floating point number
  bigFloat := -4.56E100;  // Infinite negative floating point number
  int      := -7;         // Negative integer

  Console.WriteLine('float    = {0}', float.ToString);
  Console.WriteLine('bigFloat = {0}', bigFloat.ToString);
  Console.WriteLine('int      = {0}', int.ToString);

  // Get the absolute values
  float    := System.Math.Abs(float);
  bigFloat := System.Math.Abs(bigFloat);
  int      := System.Math.Abs(int);

  Console.WriteLine('float    = {0}', float.ToString);
  Console.WriteLine('bigFloat = {0}', bigFloat.ToString);
  Console.WriteLine('int      = {0}', int.ToString);

  Console.ReadLine;
end.
Show full unit code
  float    = -1.5
  bigFloat = -Infinity
  int      = -7
  float    = 1.5
  bigFloat = Infinity
  int      = 7
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author