// JavaScript Document
function FormatNumber(myNumber,Decimals,Separator)
{
 // **********************************************************
 // Placed in the public domain by Affordable Production Tools
 // March 21, 1998
 // Web site: http://www.aptools.com/
 //
 // November 24, 1998 -- Error which allowed a null value
 // to remain null fixed. Now forces value to 0.
 //
 // October 28, 2001 -- Modified to provide leading 0 for fractional number
 // less than 1.
 //
 // This function accepts a number to format and number
 // specifying the number of decimal places to format to. May
 // optionally use a separator other than '.' if specified.
 //
 // If no decimals are specified, the function defaults to
 // two decimal places. If no number is passed, the function
 // defaults to 0. Decimal separator defaults to '.' .
 //
 // If the number passed is too large to format as a decimal
 // number (e.g.: 1.23e+25), or if the conversion process
 // results in such a number, the original number is returned
 // unchanged.
 // **********************************************************
 myNumber += ""          // Force argument to string.
 Decimals += ""        // Force argument to string.
 Separator += ""       // Force argument to string.
 if((Separator == "") || (Separator.length > 1))
  Separator = "."
 if(myNumber.length == 0)
  myNumber = "0"
 var OriginalmyNumber = myNumber  // Save for myNumber too large.
 var Sign = 1
 var Pad = ""
 var Count = 0
 // If no myNumber passed, force myNumber to 0.
 if(parseFloat(myNumber)){
  myNumber = parseFloat(myNumber)} else {
  myNumber = 0}
 // If no decimals passed, default decimals to 2.
 if((parseInt(Decimals,10)) || (parseInt(Decimals,10) == 0)){
  Decimals = parseInt(Decimals,10)} else {
  Decimals = 2}
 if(myNumber < 0)
 {
  Sign = -1         // Remember sign of myNumber.
  myNumber *= Sign    // Force absolute value of myNumber.
 }
 if(Decimals < 0)
  Decimals *= -1    // Force absolute value of Decimals.
 // Next, convert myNumber to rounded integer and force to string value.
 // (myNumber contains 1 extra digit used to force rounding)
 myNumber = "" + Math.floor(myNumber * Math.pow(10,Decimals + 1) + 5)
 if((myNumber.substring(1,2) == '.')||((myNumber + '')=='NaN'))
  return(OriginalmyNumber) // myNumber too large to format as specified.
 // If length of myNumber is less than myNumber of decimals requested +1,
 // pad with zeros to requested length.
 if(myNumber.length < Decimals +1) // Construct pad string.
 {
  for(Count = myNumber.length; Count <= Decimals; Count++)
   Pad += "0"
 }
 myNumber = Pad + myNumber // Pad myNumber as needed.
 if(Decimals == 0){
  // Drop extra digit -- Decimal portion is formatted.
  myNumber = myNumber.substring(0, myNumber.length -1)} else {
  // Or, format myNumber with decimal point and drop extra decimal digit.
 myNumber = myNumber.substring(0,myNumber.length - Decimals -1) +
          Separator +
          myNumber.substring(myNumber.length - Decimals -1,
          myNumber.length -1)}
 if((myNumber == "") || (parseFloat(myNumber) < 1))
  myNumber="0"+myNumber // Force leading 0 for |myNumber| less than 1.
 if(Sign == -1)
  myNumber = "-" + myNumber  // Set sign of myNumber.
 return(myNumber)
}
