RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
System.Frac Function

Returns the fractional part of a real number.

Pascal
function Frac(const X: Extended): Extended;
C++
Extended Frac(const Extended X);

In Delphi code, the Frac function returns the fractional part of the argument X. 

X is a real-type expression. The result is the fractional part of X; that is, Frac(X) = X - Int(X).  

Delphi Examples: 

 

{
This example illustrates the use of the System Frac function.
The number in the text edit can be a negative or positive
real number.
Notice how the type passed (R) matters.
}
procedure TForm1.Button1Click(Sender: TObject);
var
 R: Extended;
begin
  R := StrToFloat(Edit1.Text);
  ListBox1.Items.Add(FloatToStr(Frac(R)));
end;

procedure TForm1.Button2Click(Sender: TObject);
var
 R: Real;
begin
  R := StrToFloat(Edit1.Text);
  ListBox1.Items.Add(FloatToStr(Frac(R)));
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!