# convert amount from figures to words
# @url http://codelife.me/blog/2013/03/09/convert-amount-from-figures-to-words-by-coffeescript/
if process.argv.length >= 3
n = parseFloat(process.argv[2]).toFixed(2)
digits = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]
units = [["元", "万", "亿"],["", "拾", "佰", "仟"]]
[head, n] = if n < 0 then ['负', -n] else ['', n]
fractionalPart = Math.round(n * 100) % 100
s += (digits[Math.floor(fractionalPart / Math.pow(10, 1-i)) % 10] + fractions[i])
for i in [0..units[0].length - 1] when intPart > 0
for j in [0..units[1].length - 1] when n > 0
p = digits[intPart % 10] + units[1][j] + p
intPart = Math.floor(intPart / 10)
s = p.replace(/(零.)*零$/g, "").replace(/^$/g, "零") + units[0][i] + s
console.log(head + s.replace(/(零.)*零元/g, "元")