// 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
js------科学计数法转换为正常小数
原文地址:https://www.cnblogs.com/qddyh/p/10463450.html