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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
program tstrreal4;
{ test for issue #13722 by Zeljan Rikalo}
uses SysUtils;
procedure test;
var
s: string;
r: double;
DS: Char;
begin
DecimalSeparator := '.';
DS := DecimalSeparator;
r := 0.001;
s := FloatToStrF(r, ffGeneral, 12, 2);
{must print 0.001 }
writeln(s);
if (s <> '0'+DS+'001') then
halt(1);
s := FloatToStrF(r, ffFixed, 12, 2);
{must print 0.00 }
writeln(s);
if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffNumber, 12, 2);
{must print 0.00 }
writeln(s);
if (s <> '0'+DS+'00') then
halt(1);
r := -0.00001;
s := FloatToStrF(r, ffGeneral, 12, 2);
{must print -0.00001 }
writeln(s);
{$IFDEF FPC}
if (s <> '-0'+DS+'00001') then
{$ELSE}
if (s <> '-1E-05') then // is this DCC bug ?
{$ENDIF}
halt(1);
s := FloatToStrF(r, ffExponent, 12, 2);
{must print -1.00000000000E-05 }
writeln(s);
if (s <> '-1'+DS+'00000000000E-05') then
halt(1);
s := FloatToStrF(r, ffFixed, 12, 2);
{must print 0.00 }
writeln(s);
if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffNumber, 12, 2);
{must print 0.00 }
writeln(s);
if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffCurrency, 12, 2);
{must print without leading zero }
writeln(s);
if (length(s) > 0) and
((Pos('-', s) > 0) or ((Pos('(', s) > 0) and (Pos(')', s) > 0))) then
halt(1);
r := -0.00000;
s := FloatToStrF(r, ffGeneral, 12, 2);
{must print 0 }
writeln(s);
if (s <> '0') then
halt(1);
s := FloatToStrF(r, ffExponent, 12, 2);
{must print 0.00 }
writeln(s);
if (s <> '0'+DS+'00000000000E+00') then
halt(1);
s := FloatToStrF(r, ffFixed, 12, 2);
{must print 0.00 }
writeln(s);
if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffNumber, 12, 2);
{must print 0.00 }
writeln(s);
if (s <> '0'+DS+'00') then
halt(1);
s := FloatToStrF(r, ffCurrency, 12, 2);
{must print without leading zero }
writeln(s);
if (length(s) > 0) and
((Pos('-', s) > 0) or ((Pos('(', s) > 0) and (Pos(')', s) > 0))) then
halt(1);
// Now check if we remove leading negative sign by mistake
r := -0.00001;
s := FloatToStrF(r, ffGeneral, 12, 5);
{must print -0.00001 }
writeln(s);
{$IFDEF FPC}
if (s <> '-0'+DS+'00001') then
{$ELSE}
if (s <> '-1E-5') then // is this DCC bug ?
{$ENDIF}
halt(1);
s := FloatToStrF(r, ffExponent, 12, 5);
{must print -0.00001 }
writeln(s);
{$IFDEF FPC}
if (s <> '-1'+DS+'00000000000E-0005') then
{$ELSE}
if (s <> '-1.00000000000E-5') then
{$ENDIF}
halt(1);
s := FloatToStrF(r, ffFixed, 12, 5);
{must print 0.00 }
writeln(s);
if (s <> '-0'+DS+'00001') then
halt(1);
s := FloatToStrF(r, ffNumber, 12, 5);
{must print 0.00 }
writeln(s);
if (s <> '-0'+DS+'00001') then
halt(1);
s := FloatToStrF(r, ffCurrency, 12, 5);
{here we check for various currency negative formats.
There's bug in rtl cause NegCurFormat can be > 10
and in that case it isn't handled by FloatToStrIntl().
So that's why we check NegCurFormat range here.}
writeln(s);
if (length(s) > 0) and (NegCurrFormat in [0..10]) and
(Pos('-', s) = 0) and (Pos('(', s) = 0) and (Pos(')', s) = 0) then
halt(1);
writeln('Tests for FloatToStrF(): SUCCESS');
end;
begin
test;
end.
|