//formatSci.js
//David N. Blauch  Version 1.0  Copyright 2000
//
//parses a numerical value and returns a string with scientific notation
//x is the numerical value
//nL is the total length of the string returned
//nD is the number of decimal places to be displayed
function formatSci(x,nL,nD) 	
{
	var s = "";

     if (x<1E-99 && x>-1E-99) {
        //zero
        s = "0.";
        var i = 0;
        while (i<nD) {
              s += "0";
              i++;
        }
        s += "E+00";
        return s;
     }

     var ex = Math.floor(Math.log(Math.abs(x))/Math.LN10);
     var m = x*Math.exp(-ex*Math.LN10);

     if ((m+Math.exp(-nD*Math.LN10)/2.0)>=10) {   //round up if necessary
        m /= 10;
        ex++;
     }

     s += formatDec(m,nL-5,nD);

     if (ex>=0) s += "E+";
     else {
        s += "E-";
        ex = Math.abs(ex);
     }

     var se = String(ex);
     if (se.length==2) s += se;
     else s += "0"+se;

     while (nL > s.length) s = " "+s;

     return s;
  }

















