JS:浏览器上大于 e+21 的 大数字处理方式

let num = this.changeCount();
changeCount(){
	let count = new BigNumber(this.num).times('1e18').toString()
	if (count.toString().indexOf('e+') > -1) {
		count = this.checkKeXue(count)
	} else {
		count = Number(count).toFixed()
	}
	return count
},
checkKeXue(num) {
	let kstr = num.toString();
	let kFanelStr = ''
	let kArr = []
	let kstrprev = ''
	let kstrlast = ''
	let fanelKstrprev = ''
	let kprevArr = ''
	let kprevStr1 = ''
	let kprevStr2 = ''
	let digitsNum = 0
	console.log(kstr.indexOf('e+') > -1)
	if (kstr.indexOf('e+') > -1) {
		kArr = kstr.split('e+')
		kstrprev = kArr[0]
		console.log(kstrprev)
		if (kstrprev.indexOf('.') > -1) {
			kprevArr = kstrprev.split('.')
			kprevStr1 = kprevArr[0]
			kprevStr2 = kprevArr[1]
			digitsNum = kprevStr2.length
			fanelKstrprev = kprevStr1 + '' + kprevStr2
		} else {
			fanelKstrprev = kstrprev
		}

		kstrlast = kArr[1]
		kFanelStr = fanelKstrprev + '' + this.creatMoreZero(Number(kstrlast) - digitsNum)
		console.log(fanelKstrprev)
		console.log(this.creatMoreZero(Number(kstrlast)))
		console.log(kFanelStr)
	} else {
		kFanelStr = num
	}
	return kFanelStr
},

你可能感兴趣的:(javascript,javascript,前端,vue.js)