Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Hot Offer
Save your money!
Featured
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

News Tips .NET Software VCL Software Partners  

Get vulgar fraction from decimal
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


Our Partner
DevArchive.com
Recommended
just4fun
Useful Resources
Win32.hlp Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
Newsletters
Subscribe to our news!    Subscribe to our news!


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software