Currency: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments.
(Added AppleScript.)
m (→‎{{header|REXX}}: added/changed whitespace and comments.)
Line 1,217:
numeric digits 200 /*support for gihugic numbers.*/
taxRate= 7.65 /*number is: nn or nn% */
if right(taxRate, 1)\=='%' then taxRate= taxRate / 100 /*handle plain tax rate number*/
taxRate= strip(taxRate, , '%') /*strip the % (if present).*/
item. =; items=0 0 /*zero out the register. */
item.1 = '4000000000000000 $5.50 hamburger' /*the first item purchased. */
item.2 = ' 2 $2.86 milkshake' /* " second " " */
say center('quantity', 22) center("item", 22) center('price', 22)
hdr= center('', 27, "─") center('', 20, "─") center('', 27, "─"); say hdr
say hdr; total= 0
total=0
do j=1 while item.j\=='' /*calculate the total and tax.*/
parse var item.j quantity price thing /*ring up an item on register.*/
Line 1,231:
subtotal = quantity * price /*calculate the sub-total.*/
total = total + subtotal /* " " running total.*/
say right(quantity, 27) left(thing, 20) show$(subtotal)
end /*j*/
say /*display a blank line for separator. */
say translate(hdr, '═', "─") /*display the separator part of the hdr*/
tax= format(total * taxRate, , 2) /*round the total tax for all the items*/
say right(items "(items)", 35) right('total=', 12) show$(total)
say right('tax at' (taxRate * 100 / 1)"%=", 48) show$(tax)
Line 1,242:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
show$: return right( '$'arg(1), 27) /*right─justify and format a number. */</lang>
{{out|output|text=&nbsp; (attempting to mimic a check-out register to some degree):}}
<pre>
Line 1,261:
numeric digits 200 /*support for gihugic numbers.*/
taxRate= 7.65 /*number is: nn or nn% */
if right(taxRate, 1)\=='%' then taxRate= taxRate / 100 /*handle plain tax rate number*/
taxRate=strip(taxRate, , '%') /*strip the % (if present).*/
item. =; items=0 0 /*zero out the register. */
item.1 = '4000000000000000 $5.50 hamburger' /*the first item purchased. */
item.2 = ' 2 $2.86 milkshake' /* " second " " */
say center('quantity', 22) center("item", 22) center('price', 22)
hdr= center('', 27 ,"─") center('', 20, "─") center('', 27, "─"); say hdr
say hdr; total=0
total=0
do j=1 while item.j\=='' /*calculate the total and tax.*/
parse var item.j quantity price thing /*ring up an item on register.*/
Line 1,275:
subtotal = quantity * price /*calculate the sub-total.*/
total = total + subtotal /* " " running total.*/
say right(quantity, 27) left(thing, 20) show$(subtotal)
end /*j*/
say /*display a blank line for separator. */
say translate(hdr, '═', "─") /*display the separator part of the hdr*/
tax= format(total * taxRate, , 2) /*round the total tax for all the items*/
say right( commas(items "(items)"), 35) right('total=', 12) show$(total)
say right('tax at' (taxRate * 100 / 1)"%=", 48) show$(tax)
say
say right('grand total=', 48) show$(total + tax)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: procedure; parse arg _; n= _'.9'; #= 123456789; b= verify(n, #, "M")
e= verify(n, #'0', , verify(n, #"0.", 'M') ) - 4 /* [↓] commatize number*/
do j=e to b by -3; _= insert(',', _, j); end /*j*/; return _
/*──────────────────────────────────────────────────────────────────────────────────────*/
show$: return right( commas( '$'arg(1) ), 27) /*right─justify and format a number. */</lang>
{{out|output|text=&nbsp; with commas in the larger numbers:}}
<pre>