function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = autoRound(i,2,'B');
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

/**
 * Gaussian rounding (aka Banker's rounding) is a method of statistically
 * unbiased rounding. It ensures against bias when rounding at x.5 by
 * rounding x.5 towards the nearest even number. Regular rounding has a
 * built-in upwards bias.
 */
function gaussianRound(x) {
	return parseFloat(autoRound(x,2,'B'));
/*    var absolute = Math.abs(x);
    var sign     = x == 0 ? 0 : (x < 0 ? -1 : 1);
    var floored  = Math.floor(absolute);
    if (absolute - floored != 0.5) {
        return Math.round(absolute) * sign;
    }
    if (floored % 2 == 1) {
        // Closest even is up.
        return Math.ceil(absolute) * sign;
    }
    // Closest even is down.
    return floored * sign;
*/
}

function autoRound(iv, mDec, rMethod){ // rounding function via text
		var ivRounded = '';
		var i = 0;
		var nSign = ''; 
		iv = iv + ''; // convert to string
		if (iv.charAt(0) == '-'){ //Checks if the iv (input Value)is a negative value
			nSign = (iv * 1 === 0) ? '' : '-'; //determines if the value is zero - if zero no negative sign
			iv = iv.replace('-', ''); // removes the negative sign will be added back later if required			
		}
		var dPos = iv.lastIndexOf('.'); //decimal postion as an integer
		if (dPos === 0){// prefix with a zero if the decimal point is the first character
			iv = '0' + iv;
			dPos = 1;
		}
		if (dPos == -1 || dPos == iv.length - 1){//Has an integer been passed in?
			if (mDec > 0){
				ivRounded = (dPos == -1) ? iv + '.' : iv;
				for(i = 0; i < mDec; i++){ //pads with zero
						ivRounded += '0';
				}
				return nSign + ivRounded;
			}
			else {
				return nSign + iv;
			}
		}
		var cDec = (iv.length - 1) - dPos;//checks decimal places to determine if rounding is required
		if (cDec == mDec){
			return nSign + iv; //If true return value no rounding required
		}
		if (cDec < mDec){ //Do we already have less than the number of decimal places we want?
			ivRounded = iv; //If so, pad out with zeros
			for(i = cDec; i < mDec; i++){
				ivRounded += '0';
			}
			return nSign + ivRounded;
		}
		var rLength = dPos + mDec; //rounded length of the string after rounding 
		var tRound = iv.charAt(rLength + 1) * 1; // test round
		var ivArray = [];// new array 
		for(i = 0; i <= rLength; i++){ //populate ivArray with each digit in rLength
			ivArray[i] = iv.charAt(i);
		}
		var odd = (iv.charAt(rLength) == '.') ? (iv.charAt(rLength - 1) % 2) : (iv.charAt(rLength) % 2); 
		if ((tRound > 4 && rMethod === 'S') || //Round half up symetric
			(tRound > 4 && rMethod === 'A' && nSign === '') || //Round half up asymetric positive values
			(tRound > 5 && rMethod === 'A' && nSign == '-') || //Round half up asymetric negative values
			(tRound > 5 && rMethod === 's') || //Round half down symetric
			(tRound > 5 && rMethod === 'a' && nSign === '') || //Round half down asymetric positive values
			(tRound > 4 && rMethod === 'a' && nSign == '-') || //Round half down asymetric negative values
			(tRound > 5 && rMethod === 'B') || //Round half even "Banker's Rounding"
			(tRound == 5 && rMethod === 'B' && odd == 1) || //Round half even "Banker's Rounding"
			(tRound > 0 && rMethod === 'C' && nSign === '') || //Round to ceiling toward positive infinite
			(tRound > 0 && rMethod === 'F' && nSign == '-') || //Round to floor toward negative inifinte			
			(tRound > 0 && rMethod === 'U')){ //round up away from zero 
			for(i = (ivArray.length - 1); i >= 0; i--){ //Round up the last digit if required, and continue until no more 9's are found
				if (ivArray[i] == '.'){
					continue;
				}
				ivArray[i]++;
				if (ivArray[i] < 10){ //if i does not equal 10 no more round up required
					break;
				}
			}
		}
		for (i=0; i <= rLength; i++){ //Reconstruct the string, converting any 10's to 0's
			if (ivArray[i] == '.' || ivArray[i] < 10 || i === 0){//routine to reconstruct non '10'
				ivRounded += ivArray[i];
			}
			else { // converts 10's to 0
				ivRounded += '0';
			}
		}
		if (mDec === 0){ //If there are no decimal places, we don't need a decimal point
			ivRounded = ivRounded.replace('.', '');
		}
		return nSign + ivRounded; //return rounded value
	}
