Price fraction: Difference between revisions

Updated D entry
(Updated D entry)
Line 584:
 
=={{header|D}}==
<lang d>import std.stdio: writeln;
 
double priceRounder(in double price) pure nothrow
in {
in { assert(price >= 0 && price <= 1.0); }
} body {
enum cin = [.06, .11, .16, .21, .26, .31, .36, .41, .46, .51,
enum cin = [.5606, .6111, .6616, .7121, .7626, .8131, .8636, .9141, .9646, 1.01];51,
enum cout = [ .1056, .1861, .2666, .3271, .3876, .4481, .5086, .5491, .5896, 1.62,01];
enum cout = [.6610, .7018, .7426, .7832, .8238, .8644, .9050, .9454, .9858, 1.00];62,
enum cin = [ .0666, .1170, .1674, .2178, .2682, .3186, .3690, .4194, .4698, 1.51,00];
foreach (i, p; cin)
foreach (i, if (p; >= pricecin)
if (p >= return cout[i];price)
assert(0) return cout[i];
}assert(0);
}
 
void main() {
Line 603 ⟶ 604:
writeln(priceRounder(price));
}</lang>
{{out}}
Output:
<pre>0.82
0.9