// JavaScript Documentfunction setDecimals(number){	// need to see if there is a minus	// If so, flag it, and remove and place back at the end	if (number.indexOf('-') != -1){		var numberIsMinus = true;		number = number.substring(1, number.length);		} else {		var numberIsMinus = false;		}	// check for decimal place	// if not there, flag it and don't try to add it or subtract 3 from the number	if (number.indexOf('.') != -1){		var numberIsDecimal = true;		// remove decimals at the end and count the length. these will be added back on at the end		var numberLength = number.length - 3;		} else {		var numberIsDecimal = false;		var numberLength = number.length;		}	// see how many seperators are nessecary - eg. number len / 3	var numberDecimals = parseInt(numberLength / 3);	var numberRemainder = numberLength % 3; 					// gives the remiander left		// start the loop to chop, insert comma using subStr function	var position = 0; 																// determins the left position of the string we're cutting from	var numberSegment = '';															// the new segment cut from the original string	var newNumber = '';												// the new string with commas		if (numberDecimals > 0){										// test that we have a long number		if (numberRemainder > 0){			numberSegment = number.substring(0, numberRemainder);					// start with the remainding number on right			position = numberRemainder											// position keeps track of where to cut from			newNumber = newNumber + numberSegment + ',';									// add the first comma			} else {			position = 0;			}		for (x = 1; x < numberDecimals + 1; x++){			numberSegment = number.substring(position, position + 3);			newNumber = newNumber + numberSegment;			if (x != numberDecimals){ 				newNumber = newNumber + ',';						// build in the new segment				}			position = position + 3;										// move to the new position			}		// test for decimal flag		// if so, stick the decimals back in, otherwise leave it		if (numberIsDecimal){			newNumber = newNumber + number.substring(numberLength, numberLength + 3); 			// stick in the final decimals			} 		}	else {			newNumber = number;				// do this if there was no cutting		}	// check for minus - if so, stick back in	if (numberIsMinus){		newNumber = '-' + newNumber;	}	return newNumber;}function getDec(val,places,sep) {	// This function takes two arguments:	//   (string || number)  val	//            (integer)  places	//             (string)  sep	// val is the numeric string or number to parse	// places represents the number of decimal	// places to return at the end of the parse.	// sep is an optional string to be used to separate	// the whole units from the decimal units (default: '.')	val = '' + val;		// Implicitly cast val to (string)		if (!sep) {		sep = '.';		// If separator isn't specified, then use a decimal point '.'	}		if (!places) { places = 0; }	places = parseInt(places);		// Make sure places is an integer		if (!parseInt(val)) {		// If val is null, zero, NaN, or not specified, then		// assume val to be zero.  Add 'places' number of zeros after		// the separator 'sep', and then return the value.  We're done here.		val = '0';		if (places > 0) {			val += sep;			while (val.substring((val.indexOf(sep))).length <= places) {				val += '0';			}		}		return val;	}		if ((val.indexOf('.') > -1) && (sep != '.')) {		val = val.substring(0,val.indexOf('.')) + sep + val.substring(val.indexOf('.')+1);			// If we're using a separator other than '.' then convert now.	}			if (val.indexOf(sep) > -1) {		// If our val has a separator, then cut our value		// into pre and post 'decimal' based upon the separator.		pre = val.substring(0,val.indexOf(sep));		post = val.substring(val.indexOf(sep)+1);	} else {		// Otherwise pre gets everything and post gets nothing.		pre = val;		post = '';	}		if (places > 0) {		// If we're dealing with a decimal then...				post = post.substring(0,(places+1));			// We care most about the digit after 'places'				if (post.length > places) {			// If we have trailing decimal places then...						if ( parseInt(post.substring(post.length - 1)) > 4 ) {				post = '' + Math.round(parseInt(post) / 10);				//post = '' + post.substring(0,post.length - 2) + (1/Math.pow(10,places));				//post = ('' + post.substring(0,post.length - 2)) + (parseInt(post.substring(post.length - 1)) + 1);			} else {				post = '' + Math.round(parseInt(post));			}		}				if (post.length > places) {			post = '' + Math.round(parseInt(post.substring(0,places)));		} else if (post.length < places) {			while (post.length < places) {				post += '0';			}		}		} else {		if (parseInt((post.substring(0,1))) > 4) {			pre = '' + (parseInt(pre) + 1);		} else {			pre = '' + (parseInt(pre));			}		post = '';	}		sep = (post.length > 0) ? sep : '';		// Should we use a separator?	val = pre + sep + post;		// Rebuild val	return val;}
