RosettaCodeData/Task/Currency/11l/currency.11l
2023-07-01 13:44:08 -04:00

24 lines
791 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

F currency(units, subunits)
R BigInt(units) * 100 + subunits
F currency_from_str(s)
V (units, subunits) = s.split(.)
R BigInt(units) * 100 + Int(subunits)
F percentage(a, num, denom)
R (a * num * 10 I/ denom + 5) I/ 10
F to_str(c)
R String(c I/ 100).#02.format(c % 100)
V hamburgers = currency(5, 50) * 4'000'000'000'000'000
V milkshakes = currency_from_str(2.86) * 2
V beforeTax = hamburgers + milkshakes
V tax = percentage(beforeTax, 765, 10'000)
V total = beforeTax + tax
V maxlen = max(to_str(beforeTax).len, to_str(tax).len, to_str(total).len)
print(Total price before tax: to_str(beforeTax).rjust(maxlen))
print(Tax: to_str(tax).rjust(maxlen))
print(Total with tax: to_str(total).rjust(maxlen))