-
Notifications
You must be signed in to change notification settings - Fork 31
/
UFor.pas
99 lines (89 loc) · 2.08 KB
/
UFor.pas
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
unit UFor;
interface
function points(d : boolean; t : string; m : integer): string;
function toreal(r : string): real;
function rtostr(r : real): string;
function plslop(o, c: string; back, buys: boolean): string;
function plslom(o, c: string; back, buys: boolean; size, amnt, intr: string): string;
function chkprc(o, c, q, b: string): boolean;
implementation
uses SysUtils;
function points;
var s : string;
p,
i,
e : integer;
begin
s := t;
if pos('.', s) = 0 then s := s + '.';
while length(s) < 6 do s := s + '0';
p := pos('.', s);
s := copy(s, 1, p - 1) + copy(s, p + 1, 6 - p);
val(s, i, e);
if d then inc(i, m) else dec(i, m);
s := inttostr(i);
while length(s) < 5 do s := '0' + s;
s := copy(s, 1, p - 1) + '.' + copy(s, p, 6 - p);
points := s;
end;
function toreal(r: string): real;
var f : real;
i : integer;
s : string;
begin
S := R;
val(trim(S), F, I);
if (i > 0) and (I < length(S)) then begin
if S[I] = '.' then S[I] := ',' else
if S[I] = ',' then S[i] := '.';
val(trim(S), F, I);
end;
result := F;
end;
function rtostr;
var s : string;
begin
str(r:5:2, s);
rtostr := s;
end;
function plslop;
var op,
cl : real;
j : integer;
begin
op := toreal(o);
cl := toreal(c);
repeat
op := op * 10;
cl := cl * 10;
until op > 3000;
j := round(cl - op);
if back xor buys then j := -j;
plslop := inttostr(j);
end;
function plslom;
var op, cl: real;
dd: real;
begin
plslom := '0';
op := toreal(o);
cl := toreal(c);
if (op = 0) or (cl = 0) then exit;
if back then dd := cl - op
else dd := 1/op - 1/cl;
dd := dd * toreal(size);
if back xor buys then dd := -dd;
dd := dd * strtoint(amnt) - toreal(intr);
plslom := rtostr(dd);
end;
function chkprc;
var op, cl: real;
bk, sb: boolean;
begin
op := toreal(o);
cl := toreal(c);
bk := (q = 'EUR') or (q = 'GBP');
sb := (b = 'Buy');
chkprc := (op >= cl) xor (bk xor sb);
end;
end.