Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack - special offer!

Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

WinAPI Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
cdtrrracks.com new!

Blogspot  greatis.blogspot.com

Get vulgar fraction from decimal - Mathematics - Tips & Tricks - Greatis Delphi Pages

This is a algorithm for getting vulgar fraction from decimal fraction.


function HOD(x, y: Integer): Integer;
begin
  if (x mod y)<>0 then
    Result:=HOD(y, x mod y)
  else Result:=y;
end;

procedure Elements(St: string; var x,y: Real);
var
  Denom, i, L, Max: Integer;
begin
  Denom:=1;
  L:=Length(St);
  for i:=1 to L do
    Denom:=Denom*10;
  Max:=HOD(Denom, StrToInt(St));
  y:=Denom/Max;
  x:=StrToInt(St)/Max;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  P, Max: Integer;
  St: string;
  x, y: Real;
begin
  P:=Pos('.', Edit1.Text);
  if P<>0 then
  begin
    Label6.Caption:=Copy(Edit1.Text, 1, P-1);
    St:=Copy(Edit1.Text, P+1, Length(Edit1.Text)-P);
    Elements(St, x, y);
    Label2.Caption:=FloatToStr(x);
    Label4.Caption:=FloatToStr(y);
  end
  else
  begin
    Label6.Caption:=Edit1.Text;
    Label2.Caption:='1';
    Label4.Caption:='1';
  end;
end;
For more
Delphi Help

Download source