| |
| Getting the Lowest common denominator. |
 |
How do I convert two numbers representing a ratio to a string
that represents a fraction of the lowest common denominator?
The following example demonstrates a technique based on
equations originally solved by Euclid in approx. 300 B.C. : Example: function GetFracStr(Num : integer;
Num2 : integer) : string;
var
N : integer;
N2 : integer;
Tmp : integer;
begin
if Num < Num2 then begin
N := Num ;
N2 := Num2;
end else begin
N := Num2;
N2 := Num ;
end;
Tmp := N2 mod N ;
while Tmp <> 0 do begin
N2 := N ;
N := Tmp;
Tmp := N2 mod N ;
end;
result := IntToStr(Num div N ) + '/' + IntToStr(Num2 div N );
end; procedure TForm .Button Click(Sender: TObject);
begin
Memo .Lines.Add(GetFracStr(2, 64));
end;
7/ 6/98 4:3 :28 PM
|
|
| Hits/month |
2,500,000+ |
Downloads (Since May 2000) |
7,393,709 |
| Total Files |
6,023 |
| Forum msgs |
7,670 |
| Articles/FAQs |
70+/900+ |
Top Selling Software at Amazon
|