jQuery技术:在javascript中读取excel会将长数字转换为指数

我正在使用SheetJs读取excel文件,但问题是它将像3577888990098这样的长数字转换为指数如3.52E+12

这个问题不重复,因为:

文件列可以是随机的,系统不知道哪些是数字,哪些是字符串(字母)或两者。

那么如何摆脱这个呢?

这是我的代码:

 function handleFileSelect(evt) { var files = evt.target.files; var i, f; //Loop through files for (i = 0, f = files[i]; i != files.length; ++i) { var name = f.name; const reader = new FileReader(); reader.onload = (evt) => { /* Parse data */ const bstr = evt.target.result; const wb = XLSX.read(bstr, {type:'binary'}); /* Get first worksheet */ const wsname = wb.SheetNames[0]; const ws = wb.Sheets[wsname]; /* Convert array of arrays */ const data = XLSX.utils.sheet_to_csv(ws, {header:1}); /* Update state */ console.log("DATA>>>"+data); }; reader.readAsBinaryString(f); } } 

    如何仅对Number对象使用toFixed()

     var x = 3577888990098; var y = '3577888990098'; if(typeof(x) === 'number') { x = x.toFixed(); // it will not convert it to exponential. } 

    我已经解决了这个问题:

     //Assuming there will not be any "+" or "E+" in any values of sheet. if(cell_data[cell_count].indexOf('E+') !== -1 || cell_data[cell_count].indexOf('+') !== -1) { console.log(cell_data[cell_count] +" IS EXPONENTIAL"); fixedNumber = Number(cell_data[cell_count]) // it will not convert exponential to number. onerow.push(fixedNumber); }else{ onerow.push(cell_data[cell_count]); } 

    由于没有JS函数来检查值是否为指数。

      以上就是jQuery教程分享在javascript中读取excel会将长数字转换为指数相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/561290.html

      (0)
      上一篇 2021年2月4日
      下一篇 2021年2月4日

      精彩推荐