/*! * accounting.js v0.4.2 * Copyright 2014 Open Exchange Rates * * Freely distributable under the MIT license. * Portions of accounting.js are inspired or borrowed from underscore.js * * Full details and documentation: * //openexchangerates.github.io/accounting.js/ */ (function(root,undefined){var lib={};lib.version='0.4.2';lib.settings={currency:{symbol:"$",format:"%s%v",decimal:".",thousand:",",precision:2,grouping:3},number:{precision:0,grouping:3,thousand:",",decimal:"."}};var nativeMap=Array.prototype.map,nativeIsArray=Array.isArray,toString=Object.prototype.toString;function isString(obj){return!!(obj===''||(obj&&obj.charCodeAt&&obj.substr));} function isArray(obj){return nativeIsArray?nativeIsArray(obj):toString.call(obj)==='[object Array]';} function isObject(obj){return obj&&toString.call(obj)==='[object Object]';} function defaults(object,defs){var key;object=object||{};defs=defs||{};for(key in defs){if(defs.hasOwnProperty(key)){if(object[key]==null)object[key]=defs[key];}} return object;} function map(obj,iterator,context){var results=[],i,j;if(!obj)return results;if(nativeMap&&obj.map===nativeMap)return obj.map(iterator,context);for(i=0,j=obj.length;i3?base.length%3:0;return negative+(mod?base.substr(0,mod)+opts.thousand:"")+base.substr(mod).replace(/(\d{3})(?=\d)/g,"$1"+opts.thousand)+(usePrecision?opts.decimal+toFixed(Math.abs(number),usePrecision).split('.')[1]:"");};var formatMoney=lib.formatMoney=function(number,symbol,precision,thousand,decimal,format){if(isArray(number)){return map(number,function(val){return formatMoney(val,symbol,precision,thousand,decimal,format);});} number=unformat(number);var opts=defaults((isObject(symbol)?symbol:{symbol:symbol,precision:precision,thousand:thousand,decimal:decimal,format:format}),lib.settings.currency),formats=checkCurrencyFormat(opts.format),useFormat=number>0?formats.pos:number<0?formats.neg:formats.zero;return useFormat.replace('%s',opts.symbol).replace('%v',formatNumber(Math.abs(number),checkPrecision(opts.precision),opts.thousand,opts.decimal));};lib.formatColumn=function(list,symbol,precision,thousand,decimal,format){if(!list||!isArray(list))return[];var opts=defaults((isObject(symbol)?symbol:{symbol:symbol,precision:precision,thousand:thousand,decimal:decimal,format:format}),lib.settings.currency),formats=checkCurrencyFormat(opts.format),padAfterSymbol=formats.pos.indexOf("%s")0?formats.pos:val<0?formats.neg:formats.zero,fVal=useFormat.replace('%s',opts.symbol).replace('%v',formatNumber(Math.abs(val),checkPrecision(opts.precision),opts.thousand,opts.decimal));if(fVal.length>maxLength)maxLength=fVal.length;return fVal;}});return map(formatted,function(val,i){if(isString(val)&&val.length