Price fraction: Difference between revisions
Content added Content deleted
(Added Bracmat) |
|||
Line 328: | Line 328: | ||
.3444635 .5 |
.3444635 .5 |
||
.0491907 .1 |
.0491907 .1 |
||
=={{header|Bracmat}}== |
|||
Bracmat has no native support for floating point variables nor for the fixed point values in the conversion table. Instead this solution just applies a string comparison. |
|||
<lang bracmat>( ( convert |
|||
= |
|||
. ("0.06"."0.10") |
|||
("0.11"."0.18") |
|||
("0.16"."0.26") |
|||
("0.21"."0.32") |
|||
("0.26"."0.38") |
|||
("0.31"."0.44") |
|||
("0.36"."0.50") |
|||
("0.41"."0.54") |
|||
("0.46"."0.58") |
|||
("0.51"."0.62") |
|||
("0.56"."0.66") |
|||
("0.61"."0.70") |
|||
("0.66"."0.74") |
|||
("0.71"."0.78") |
|||
("0.76"."0.82") |
|||
("0.81"."0.86") |
|||
("0.86"."0.90") |
|||
("0.91"."0.94") |
|||
("0.96"."0.98") |
|||
("1.01"."1.00") |
|||
: ? (>!arg.?arg) ? |
|||
& !arg |
|||
| "invalid input" |
|||
) |
|||
& -1:?n |
|||
& whl |
|||
' ( !n+1:?n:<103 |
|||
& ( @(!n:? [<2)&str$("0.0" !n):?a |
|||
| @(!n:? [<3)&str$("0." !n):?a |
|||
| @(!n:?ones [-3 ?decimals) |
|||
& str$(!ones "." !decimals):?a |
|||
) |
|||
& out$(!a "-->" convert$!a) |
|||
) |
|||
)</lang> |
|||
Output: |
|||
<pre>0.00 --> 0.10 |
|||
0.01 --> 0.10 |
|||
0.02 --> 0.10 |
|||
0.03 --> 0.10 |
|||
0.04 --> 0.10 |
|||
0.05 --> 0.10 |
|||
0.06 --> 0.18 |
|||
0.07 --> 0.18 |
|||
0.08 --> 0.18 |
|||
0.09 --> 0.18 |
|||
0.10 --> 0.18 |
|||
0.11 --> 0.26 |
|||
0.12 --> 0.26 |
|||
0.13 --> 0.26 |
|||
0.14 --> 0.26 |
|||
0.15 --> 0.26 |
|||
0.16 --> 0.32 |
|||
0.17 --> 0.32 |
|||
... |
|||
0.85 --> 0.90 |
|||
0.86 --> 0.94 |
|||
0.87 --> 0.94 |
|||
0.88 --> 0.94 |
|||
0.89 --> 0.94 |
|||
0.90 --> 0.94 |
|||
0.91 --> 0.98 |
|||
0.92 --> 0.98 |
|||
0.93 --> 0.98 |
|||
0.94 --> 0.98 |
|||
0.95 --> 0.98 |
|||
0.96 --> 1.00 |
|||
0.97 --> 1.00 |
|||
0.98 --> 1.00 |
|||
0.99 --> 1.00 |
|||
1.00 --> 1.00 |
|||
1.01 --> invalid input |
|||
1.02 --> invalid input</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |