How to convert a number into an exponential notation in JavaScript

3 Answers

0 votes
const n = 1.79769313;
 
const exp = n.toExponential();

console.log(exp);


   
/*
run:
 
1.79769313e+0
 
*/

 



answered Apr 14, 2017 by avibootz
edited Nov 21, 2024 by avibootz
0 votes
const n = 3.14;
 
const exp = n.toExponential();

console.log(exp);


   
/*
run:
 
3.14e+0
 
*/

 



answered Apr 14, 2017 by avibootz
edited Nov 21, 2024 by avibootz
0 votes
const n = 6727.9
 
const exp = n.toExponential();

console.log(exp);


   
/*
run:
 
6.7279e+3
 
*/
   

 



answered Apr 14, 2017 by avibootz
edited Nov 21, 2024 by avibootz
...