Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script for converting to e+ in javascript

function eFinder(number) {
    let c = Math.round(number);
    let a = c.toString().length - 1;
    let b = number.toString().charAt(0);
    return `${b}e+${a}`;
}

eFinder(100); would return 1e+2. This basically converts any number put in eFinder(); to scientific notation.

like image 844
Sam Avatar asked Nov 27 '25 11:11

Sam


1 Answers

Why do you want to implement it by yourself while this is part of JavaScript? Just use Number.prototype.toExponential()

const number = 100;
console.log(number.toExponential());
like image 112
Guerric P Avatar answered Nov 30 '25 01:11

Guerric P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!