Currency: Difference between revisions

752 bytes added ,  2 years ago
→‎{{header|Lua}}: added Lua solution
m (→‎{{header|F#}}: Corrected header as suggested on the Count examples/Full list/Tier 4 talk page)
(→‎{{header|Lua}}: added Lua solution)
Line 1,124:
Total price after tax : 23683000000000006.16
</pre>
 
=={{header|Lua}}==
Using the lbc library for arbitrary precision support.
<lang lua>C = setmetatable(require("bc"), {__call=function(t,...) return t.new(...) end})
C.digits(6) -- enough for .nn * .nnnn ==> .nnnnnn, follow with trunc(2) to trim trailing zeroes
 
subtot = (C"4000000000000000" * C"5.50" + C"2" * C"2.86"):trunc(2) -- cosmetic trunc
tax = (subtot * C"0.0765" + C"0.005"):trunc(2) -- rounding trunc
total = (subtot + tax):trunc(2) -- cosmetic trunc
 
print(("Before tax: %20s"):format(subtot:tostring()))
print(("Tax : %20s"):format(tax:tostring()))
print(("With tax : %20s"):format(total:tostring()))</lang>
{{out}}
<pre>Before tax: 22000000000000005.72
Tax : 1683000000000000.44
With tax : 23683000000000006.16</pre>
 
=={{header|M2000 Interpreter}}==
Anonymous user