Currency: Difference between revisions

1,830 bytes added ,  30 days ago
added RPL
m (→‎{{header|Wren}}: Minor tidy)
(added RPL)
 
(4 intermediate revisions by one other user not shown)
Line 1,984:
total price after tax : 23683000006.16
</pre>
=={{header|RPL}}==
Need for big integers.
{{works with|RPL|HP-49C}}
« →STR
'''IF''' LASTARG 9 ≤ '''THEN''' "0" SWAP + '''END'''
1 OVER SIZE 2 - SUB
LASTARG NIP 1 + DUP 1 + SUB
"$" ROT SIZE LASTARG "0" IFTE +
"." + SWAP +
» '<span style="color:blue">→CURR</span>' STO
« 100 * R→I *
DUP <span style="color:blue">→CURR</span> CLLCD 1 DISP .5 WAIT
» '<span style="color:blue">→PRICE</span>' STO
« DUPDUP FLOOR - EVAL →NUM
0.5 ≥ SWAP CEIL LASTARG FLOOR IFTE
» '<span style="color:blue">→RND</span>' STO
« 100 * R→I
OVER <span style="color:blue">→CURR</span> "TPBT" →TAG
UNROT OVER * 100000 / <span style="color:blue">→RND</span> DUP <span style="color:blue">→CURR</span> "Tax" →TAG
UNROT + <span style="color:blue">→CURR</span> "TPWT" →TAG
» '<span style="color:blue">TAX→</span>' STO
 
4000000000000000 5.50 <span style="color:blue">→PRICE</span>
2 2.86 <span style="color:blue">→PRICE</span> +
7.65 <span style="color:blue">TAX→</span>
{{out}}
<pre>
3: TPBT:"$22000000000000005.72"
2: Tax:"$1683000000000000.44"
1: TPWT:"$23683000000000006.16"
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'bigdecimal/util'
Line 2,259 ⟶ 2,294:
{{out}}
net=22000000000000005.72, tax=1683000000000000.44, total=23683000000000006.16
 
=={{header|Unicon}}==
Solution takes advantage of Unicon's FxPt class as well as Unicon's operator overloading extension.
<syntaxhighlight lang="unicon">import math
 
procedure main()
n_burgers := 4000000000000000
n_shakes := 2
 
price := FxPt(5.50) * n_burgers + FxPt(2.86) * n_shakes
tax := (price * FxPt(7.65/100)).round(2)
total := price + tax
 
write(left("Price", 10), "$", right(price.toString(),21))
write(left("Tax", 10), "$", right(tax.toString(),21))
write(left("Total", 10), "$", right(total.toString(),21))
end</syntaxhighlight>{{out}}
<pre>Price $ 22000000000000005.72
Tax $ 1683000000000000.44
Total $ 23683000000000006.16</pre>
 
=={{header|VBA}}==
1,150

edits