RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
System.Abs Function

Returns an absolute value.

Pascal
procedure Abs(X);
C++
Abs( X);

System

Abs returns the absolute value of the argument, X. 

X is an integer-type or real-type expression.  

Delphi Examples: 

 

{
This example converts negative floating point numbers and
integers to postive.
}
procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := '-2.3';
  Edit3.Text := FloatToStr(Abs(StrToFloat(Edit1.Text)));    { 2.3 }
  Edit2.Text := '-157';
  Edit4.Text := IntToStr(Abs(StrToInt(Edit2.Text)));    { 157 }
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!