diff options
Diffstat (limited to 'ipl/procs/currency.icn')
-rw-r--r-- | ipl/procs/currency.icn | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/ipl/procs/currency.icn b/ipl/procs/currency.icn new file mode 100644 index 0000000..18f3d8c --- /dev/null +++ b/ipl/procs/currency.icn @@ -0,0 +1,51 @@ +############################################################################ +# +# File: currency.icn +# +# Subject: Procedures for formatting currency +# +# Author: Robert J. Alexander +# +# Date: September 21, 1993 +# +############################################################################ +# +# This file is in the public domain. +# +############################################################################ +# +# currency() -- Formats "amount" in standard American currency format. +# "amount" can be a real, integer, or numeric string. "width" is the +# output field width, in which the amount is right adjusted. The +# returned string will be longer than "width" if necessary to preserve +# significance. "minus" is the character string to be used for +# negative amounts (default "-"), and is placed to the right of the +# amount. +# +############################################################################ + +procedure currency(amount,width,minus,decPlaces,minDollarDigits, + currencySign,decimalPoint,comma) + local sign,p + amount := real(amount) | fail + /width := 0 + /minus := "-" + /decPlaces := 2 + /minDollarDigits := 1 + /currencySign := "$" + /decimalPoint := "." + /comma := "," + if amount < 0.0 then { + sign := minus + amount := -amount + } + else sign := repl(" ",*minus) + amount := (integer(amount * 10.0 ^ (decPlaces + 1)) + 5)[1:-1] + amount := right(amount,*amount < decPlaces + minDollarDigits,"0") + p := *amount - decPlaces + 1 + amount[p:p] := decimalPoint + while (p -:= 3) > 1 do amount[p:p] := comma + amount := currencySign || amount || sign + amount := right(amount,*amount < width) + return amount +end |