Scientific Notation Functions
 sci_not002view, link (22.5 KB, 600350) source (37 KB)Fri, 7 May 04, 8:12pm UTC 

There are two functions demonstrated here:

Math.toScientific(num, [sigDigs]) returns a string with num in scientific notation. sigDigs is an optional parameter to specify the number of significant digits (valid values are integers 1 through 15). If sigDigs isn't provided it defaults to 4. In the case of error the function returns an empty string.

Math.toSigDigits(num, sigDigs) returns num as a number with sigDigs significant digits, where sigDigs is an integer from 1 to 15. If there is an error it returns NaN. Since this returns a number displaying trailing zeros when converting to a string is a problem. For example:

trace(String(Math.toSigDigits(560001, 4))); // traces 560000
// can't tell which zeros are significant and which are not

trace(String(Math.toSigDigits(0.0005, 5))); // traces 0.0005
// implies that there is only one significant digit