myNumber.toExponential( [ fractionDigits ] ) in ECMAScript 262

Return the number formatted in scientific notation, with one digit before the decimal point and a specified number of digits after.

Arguments

nametypedescription
fractionDigits Number [optional] The number of digits which sho
Return Type
String

Description

If fractionDigits is omitted, the number of digits following the decimal point will vary, showing only enough needed to uniquely identify the number.

var precision = [0,1,2,3];
var numbers = [ 0 , 0.567 , 1.5 , -0.07 , 873];
var msg="";
for (var i=0,len=numbers.length;i<len;i++){
    var n = numbers[i];
    msg += "("+n+").toExponential() is '"+n.toExponential()+"'\n";
    for (var j=0,len2=precision.length;j<len2;j++){
        var digits = precision[j];
        msg += "("+n+").toExponential("+digits+") is '"+n.toExponential(digits)+"'\n";
    }
}
/***********************************
msg is
(0).toExponential() is '0e+0'
(0).toExponential(0) is '0e+0'
(0).toExponential(1) is '0.0e+0'
(0).toExponential(2) is '0.00e+0'
(0).toExponential(3) is '0.000e+0'
(0.567).toExponential() is '5.67e-1'
(0.567).toExponential(0) is '6e-1'
(0.567).toExponential(1) is '5.7e-1'
(0.567).toExponential(2) is '5.67e-1'
(0.567).toExponential(3) is '5.670e-1'
(1.5).toExponential() is '1.5e+0'
(1.5).toExponential(0) is '2e+0'
(1.5).toExponential(1) is '1.5e+0'
(1.5).toExponential(2) is '1.50e+0'
(1.5).toExponential(3) is '1.500e+0'
(-0.07).toExponential() is '-7e-2'
(-0.07).toExponential(0) is '-7e-2'
(-0.07).toExponential(1) is '-7.0e-2'
(-0.07).toExponential(2) is '-7.00e-2'
(-0.07).toExponential(3) is '-7.000e-2'
(873).toExponential() is '8.73e+2'
(873).toExponential(0) is '9e+2'
(873).toExponential(1) is '8.7e+2'
(873).toExponential(2) is '8.73e+2'
(873).toExponential(3) is '8.730e+2'
***********************************/