Price fraction: Difference between revisions
REXX: moved to proper place and added Version 2 (translated from REXX)
Walterpachl (talk | contribs) m (→version 2: x corrected to p) |
Walterpachl (talk | contribs) (REXX: moved to proper place and added Version 2 (translated from REXX)) |
||
Line 1,672:
say price_fraction(+$value);
}</lang>
=={{header|PL/I}}==▼
declare t(20) fixed decimal (3,2) static initial (▼
.06, .11, .16, .21, .26, .31, .36, .41, .46, .51,▼
.56, .61, .66, .71, .76, .81, .86, .91, .96, 1.01);▼
declare r(20) fixed decimal (3,2) static initial (▼
.10, .18, .26, .32, .38, .44, .50, .54, .58, .62,▼
.66, .70, .74, .78, .82, .86, .90, .94, .98, 1);▼
declare x float, d fixed decimal (3,2);▼
declare i fixed binary;▼
loop:▼
do i = 1 to 20;▼
if x < t(i) then▼
do; d = r(i); leave loop; end;▼
end;▼
</lang>▼
=={{header|PicoLisp}}==
Line 1,733 ⟶ 1,715:
0.98
0.38</pre>
▲=={{header|PL/I}}==
===version 1===
▲ .06, .11, .16, .21, .26, .31, .36, .41, .46, .51,
▲ .56, .61, .66, .71, .76, .81, .86, .91, .96, 1.01);
▲ .10, .18, .26, .32, .38, .44, .50, .54, .58, .62,
▲ .66, .70, .74, .78, .82, .86, .90, .94, .98, 1);
▲declare x float, d fixed decimal (3,2);
▲declare i fixed binary;
▲loop:
▲ do i = 1 to 20;
▲ if x < t(i) then
▲ do; d = r(i); leave loop; end;
end;</lang>
===version 2===
<lang PL/I>cpt: Proc Options(main);
Dcl x Dec Fixed(4,2);
Do x=0 To 1 By 0.01;
Put Edit(x,' -> ',cp(x))(Skip,f(4,2),a,f(4,2));
cp: Proc(p) Returns(Dec Fixed(4,2));
Dcl r(20) Dec Fixed(4,2) static init(
.10, .18, .26, .32, .38, .44, .50, .54, .58, .62,
.66, .70, .74, .78, .82, .86, .90, .94, .98, 1);
Dcl p Dec Fixed(4,2);
Dcl i Bin Fixed;
i=trunc((100*p-1)/5)+1;
Return(r(i));
End;
▲ End;</lang>
=={{header|PureBasic}}==
|