unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
function lcdiv(i,j:integer):integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
i:integer;
div1,div2:integer;
begin
s:=edit1.Text;
i:=pos('.',s);
s:=copy(s,i+1,length(s));
div2:=length(s);
div1:=strtoint(s);
div2:=strtoint(Floattostr(exp(div2*ln(10))));
i:=lcdiv(div1,div2);
label1.Caption:=inttostr(div1 div i)+#13+'-'+#13+inttostr(div2 div i);
end;
function TForm1.lcdiv(i,j:integer):integer;
var d,x,g:integer;
begin
if i<j then
begin
d:=j;
x:=i;
end
else
begin
d:=i;
x:=j;
end;
repeat
g:=d mod x;
d:=x;
x:=g;
until g=0;
result:=d;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not(key in ['0'..'9','.',#8]) then key:=#0;
end;
end.