SystemArcTan (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to use the ArcTan and FloatToStr functions to approximate Pi.

Code

procedure TForm1.Button1Click(Sender: TObject);
var
  ex : Extended;
  mystring : String;
begin
  ex := 16 * ArcTan(1/5) - 4 * ArcTan(1/239); // Machin's formula
  mystring := FloatToStr(ex);
  Edit3.Text := mystring;
  Str(ex:25:23, mystring);
  Edit4.Text := mystring;
  mystring := FloatToStrF(ex, ffFixed, 35, 33);
  Edit2.Text := mystring;
  mystring := SysUtils.FormatFloat('#,##0.00000000000000000000000000;;Zero', ex);
  Edit5.Text := mystring;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  ex : Extended;
  myString : String;
begin
  ex := Pi;
//  mystring := FloatToStr(ex);
//  Str(ex:25:23, mystring);
  mystring := FloatToStrF(ex, ffFixed, 35, 33);
  Edit1.Text := mystring;
end;

Uses

Personal tools
Assistance