Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack Special Offer!


Share this page

Follow us
LinkedIn Blogspot Twitter Facebook

Related products
Ultimate Pack  hot!
iGrid Plotter  new!
Image Editor
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
Print Suite .NET
Gradient Controls .NET  new!

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#

Special
Free Software Promotion
Offers for Resellers

Hobby projects
cdtrrracks.com
books.storrre.com
in3steps.com
sovietphillumeny.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