function Convertnum (NUM_STR) {//parameter must be a string
Scientific notation characters convert to numeric characters, break the number of positive 21-bit and negative 7-bit conversions automatically
Compatible with multiple digits to the left of the decimal point, i.e. ax10^b (AEB), a non-standard range (1≤|A|<10). such as 3453.54E-6 or 3453.54E6
var resvalue = ' ',
Power = ' ',
result = NULL,
Dotindex = 0,
Resarr = [],
Sym = ";
var numstr = num_str.tostring ();
if (numstr[0] = = '-') {//if negative, turn to positive processing, remove the '-' sign first and save '-'.
Numstr = NUMSTR.SUBSTR (1);
sym = '-';
}console.log (NUMSTR)
if ((Numstr.indexof (' E ')! =-1) | | (Numstr.indexof (' e ')! =-1)) {
var regExp = new RegExp (' ^ ((\\d+.? \\d+) | (\\d+)) [Ee] {1} ((-(\\d+)) | (\\d+))) $ ', ' IG ');
result = Regexp.exec (NUMSTR);
Console.log (result);
if (result! = null) {
Resvalue = result[2];
Power = result[5];
result = NULL;
}
if (!resvalue &&!power) {return false}
Dotindex = Resvalue.indexof ('. ');
Resvalue = Resvalue.replace ('. ', ');
Resarr = Resvalue.split (");
if (number (power) >= 0) {
var subres = resvalue.substr (Dotindex);
Power = number (power);
When the number of powers is greater than the number of digits after the decimal point, add 0
for (var i=0; i<power-subres.length; i++) {
Resarr.push (' 0 ');
}
if (Power-subres.length < 0) {
Resarr.splice (dotindex+power, 0, '. ');
}
}else{
Power = power.replace ('-', ');
Power = number (power);
Index position with a power greater than or equal to the decimal point, preceded by 0
for (var i=0; i<=power-dotindex; i++) {
Resarr.unshift (' 0 ');
}
var n = power-dotindex >= 0? 1:-(Power-dotindex);
Resarr.splice (n, 0, '. ');
}
}
Resvalue = Resarr.join (");
Console.log (Sym+resvalue);
return sym+resvalue;
}
Use
Convertnum (' 3.54545E-2 ')
JS Scientific Counting method