js------科學計數法轉換為正常小數


// toD.js文件
export default (val) => {
const e = String(val)
let rex = /^([0-9])\.?([0-9]*)e-([0-9])/
if (!rex.test(e)) return val
const numArr = e.match(rex)
const n = Number('' + numArr[1] + (numArr[2] || ''))
const num = '0.' + String(Math.pow(10, Number(numArr[3]) - 1)).substr(1) + n
return num.replace(/0*$/, '') // 防止可能出現0.0001540000000的情況
}
// 用法:
import toD form './toD'

toD(2.32e-5) // 0.0000232


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM