summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/test/tstrreal3.pp
blob: 00269d3a76767d5e4363cf7585bbb49664f5df3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{ test by Graeme Geldenhuys }

{$mode delphi}
uses sysutils;


procedure test;
var
 Result: string;
 e: extended;
 r: double;
begin
 DecimalSeparator:='.';
 e := 234.502;
 Result := FloatToStrF(e, ffGeneral, 15, 0);
// Memo1.Lines.Add(Result);      { prints 234.502  }
 writeln(result);
 if (result <> '234.502') then
   halt(1);

 r := 234.502;
 Result := FloatToStrF(r, ffGeneral, 15, 0);
// Memo1.Lines.Add(Result);  { prints 234.50200000000001 }
 writeln(result);
 if (result <> '234.502') then
   halt(1);

 r := 234.501;
 Result := FloatToStrF(r, ffGeneral, 15, 0);
// Memo1.Lines.Add(Result);  { prints 234.501  Why does this work? }
 writeln(result);
 if (result <> '234.501') then
   halt(1);

 r := 7.502;
 Result := FloatToStrF(r, ffGeneral, 15, 0);
// Memo1.Lines.Add(Result);  { prints 7.502 }
 writeln(result);
 if (result <> '7.502') then
   halt(1);

 r := 8.502;
 Result := FloatToStrF(r, ffGeneral, 15, 0);
// Memo1.Lines.Add(Result);  { prints 8.502000000000001 }
 writeln(result);
 if (result <> '8.502') then
   halt(1);

 e:=0.005;
 str(e:0:2,result);
 writeln(result);
 if (result<>'0.01') then
   halt(1);
end;

begin
  test;
end.