When floating-point numbers in JS use the toString () method, when do you get scientific counting?

in some cases, the floating point number .toString () gets the form of scientific notation, while in some cases it doesn"t.
for example:
console.log (0.0004.toString ()); / / 0.0004

)

console.log (0.0000004.toString ()); / / 4e-7

)

it seems that-7 is such a threshold? How is this-7 determined?

Mar.09,2021

specified by the specification, specification link

clipboard.png

0.0004
at this time s is 4 , k is 1 , n is -3 , so it is step 8 ;

0.0000004
at this time s is 4 , k is 1 , n is -6 , so instead of step 8 , but to step 9 , you will see that step 9 is the first to output s < / Then output abs (n-1) , that is, 7 , so it adds up to '4eMurray 7' ;


when 0 is more than 5 , scientific counting is displayed by default, or there are more than 21 numbers before the decimal point.

Menu