24 lines
791 B
Text
24 lines
791 B
Text
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))
|