Price fraction: Difference between revisions

Added zkl
(Adds Clojure output)
(Added zkl)
Line 2,724:
0.18
1.00
</pre>
 
=={{header|zkl}}==
<lang zkl>fcn convert(price){ // float --> float
// < -->, increments of 0.05 but tables are easier to update
var vert=T( T(0.06, 0.10), T(0.11, 0.18), T(0.16, 0.26),
T(0.21, 0.32), T(0.26, 0.38), T(0.31, 0.44),
T(0.36, 0.50), T(0.41, 0.54), T(0.46, 0.58),
T(0.51, 0.62), T(0.56, 0.66), T(0.61, 0.70),
T(0.66, 0.74), T(0.71, 0.78), T(0.76, 0.82),
T(0.81, 0.86), T(0.86, 0.90), T(0.91, 0.94),
T(0.96, 0.98), T(1.01, 1.00), );
vert.filter1('wrap([(a,_)]){ price<a })[1]
}</lang>
<lang zkl>fcn convert2(price){ // shifting the fractional part to the integer portion
var vert=T(010, 018, 026, 032, 038, 044, 050, 054, 058, 062,
066, 070, 074, 078, 082, 086, 090, 094, 098, 100);
0.01*vert[(price*100-1)/005];
}</lang>
<lang zkl>T(0.7388727, 0.8593103, 0.826687, 0.3444635, 0.0491907).apply(convert).println();
T(0.7388727, 0.8593103, 0.826687, 0.3444635, 0.0491907).apply(convert2).println();</lang>
{{out}}
<pre>
L(0.82,0.9,0.9,0.5,0.1)
L(0.82,0.9,0.9,0.5,0.1)
</pre>
Anonymous user