<!--
/*function : format_number() 
version: 1.0.0 
This function formats a numeric value passed in to it with specified number of 
decimal values. numeric value will not be rounded. 
pnumber : numeric value to be formatted. 
decimals : number of decimal points desired. 

Author: Buddhike de Silva 
Date: 21-Nov-2002 11:16 AM*/ 

/* 
revision: 1.1.0 
Author: M. Cassim Farook 
Date: 21-Nov-2002 10:16 PM 
Notes: No offense buddhike...but i had to rewrite the code 
works for ADT (any dam thing) 
usage: x = format_number(123.999, 2) 
*/ 

/* 
revision: 1.2.0 
Authors: Buddhike de Silva 
Date: 22-Nov-2002 12:07 PM 
Notes: Optimized for best performence. 
usage: x = format_number(123.999, 2) 
*/ 

/*
 * Revision: 1.3
 * Author: Mike Robb (JS-X.com)
 * Date: May 26, 2003
 * Notes:  Changed to deal with negative numbers.
 *         Fixed length of final answer.
 *         Work-around for javascript internal math problem with rounding negative numbers.
 */
function format_number(pnumber,decimals)
{ 
  if (isNaN(pnumber)) { return 0}; 
  if (pnumber=='') { return 0}; 
  
  var IsNegative=(parseInt(pnumber)<0);
  if(IsNegative)pnumber=-pnumber;

  var snum = new String(pnumber); 
  var sec = snum.split('.'); 
  var whole = parseInt(sec[0]); 
  var result = ''; 
  if(sec.length > 1){ 
    var dec = new String(sec[1]); 
    dec = parseInt(dec)/Math.pow(10,parseInt(dec.length-decimals-1));
	Math.round(dec);
	dec = parseInt(dec)/10;
	
	if(IsNegative)
	{
	  var x = 0-dec;
      x = Math.round(x);
	  dec = - x;
	}
	else
	{
      dec = Math.round(dec);
	}

	/*
	 * If the number was rounded up from 9 to 10, and it was for 1 'decimal'
	 * then we need to add 1 to the 'whole' and set the dec to 0.
	 */
	if(decimals==1 && dec==10)
	{
	  whole+=1;
	  dec="0";
	}

    dec = String(whole) + "." + String(dec); 
    var dot = dec.indexOf('.'); 
    if(dot == -1){ 
      dec += '.'; 
      dot = dec.indexOf('.'); 
    }
	var l=parseInt(dot)+parseInt(decimals);
    while(dec.length <= l) { dec += '0'; } 
    result = dec; 
  } else{ 
    var dot; 
    var dec = new String(whole); 
    dec += '.'; 
    dot = dec.indexOf('.'); 
	var l=parseInt(dot)+parseInt(decimals);
    while(dec.length <= l) { dec += '0'; } 
    result = dec; 
  } 
  if(IsNegative)result="-"+result;
  return result; 
} 

-->