js怎么去除1e里面e?
方法一:使用 Number() 函數(shù)將科學(xué)計數(shù)法表示的字符串轉(zhuǎn)換為數(shù)字。然后,使用 toString() 方法將其轉(zhuǎn)換回字符串形式,這樣就會自動移除科學(xué)計數(shù)法中的 "e"
var num = 1e10; // 科學(xué)計數(shù)法表示的數(shù)字
var numStr = Number(num).toString(); // 轉(zhuǎn)換為字符串,自動移除 "e"
console.log(numStr); // 輸出 "10000000000"
方法二:使用正則表達(dá)式替換方法移除科學(xué)計數(shù)法中的 "e"。
?var num = 1e10; // 科學(xué)計數(shù)法表示的數(shù)字
var numStr = num.toString().replace("e", ""); // 使用 replace 方法替換 "e" 為空字符串 console.log(numStr); // 輸出 "10000000000"
vue中限制長度以及數(shù)字(包括e)?
// 封裝方法--只允許輸入正數(shù)包 export function getNum(val) { // 先把非數(shù)字的都替換掉,除了數(shù)字 val = Number(val).toString().replace(/[^\d]/g, '') return val } <el-input type="number" v-model.trim="ruleForm.height" clearable placeholder="請輸入數(shù)字" οnkeydοwn="return event.keyCode !== 69" @input="changeNumber('height',ruleForm.height,8)" />changeNumber(name, obj, len = 8) { const t = obj.length > len ? obj.slice(0, len) : obj this.$set(this.ruleForm, name, getNum(t)) }
vue中自動保存兩位小數(shù)?文章來源:http://www.zghlxwxcb.cn/news/detail-655982.html
// 封裝方法--只允許輸入數(shù)字包含小數(shù)點 export function getFloorNumber(val, saveNumber = 2) { // 先把非數(shù)字的都替換掉,除了數(shù)字 val = val.replace(/[^\d.]/g, '') val = val.replace(/\.{2,}/g, '.') val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.') const index = val.indexOf('.') if (index != -1) { const arr = val.split('.') if (arr[1].length > saveNumber) { arr[1] = arr[1].substr(0, saveNumber) } val = arr.join('.') } return val }
<el-input v-model="ruleForm.sharedArea" placeholder="請?zhí)顚懨娣e" clearable @input="changeSpliceArea('area')" @blur="changeArea('area')" />
changeSpliceArea(name, len = 8) { this.ruleForm[name] = getFloorNumber(this.ruleForm[name]) if (this.ruleForm[name].length >= len) { this.ruleForm[name] = this.ruleForm[name].substr(0, len) } }, changeArea(name) { const t = this.ruleForm[name] && this.ruleForm[name].charAt(this.ruleForm[name].length - 1) if (t == '.') { this.ruleForm[name] += '00' } }
常用工具方法文章來源地址http://www.zghlxwxcb.cn/news/detail-655982.html
// 只允許輸入數(shù)字包含負(fù)數(shù) export function getNumber(val) { const t = val.charAt(0) // 先把非數(shù)字的都替換掉,除了數(shù)字 val = val.replace(/[^\d]/g, '') // 如果第一位是負(fù)號,則允許添加 if (t === '-') { val = '-' + val } return val } // 只允許輸入正數(shù)包 export function getNum(val) { // 先把非數(shù)字的都替換掉,除了數(shù)字 val = Number(val).toString().replace(/[^\d]/g, '') return val } // 只允許輸入數(shù)字包含小數(shù)點 export function getFloorNumber(val, saveNumber = 2) { // 先把非數(shù)字的都替換掉,除了數(shù)字 val = val.replace(/[^\d.]/g, '') val = val.replace(/\.{2,}/g, '.') val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.') const index = val.indexOf('.') if (index != -1) { const arr = val.split('.') if (arr[1].length > saveNumber) { arr[1] = arr[1].substr(0, saveNumber) } val = arr.join('.') } return val } // 只允許輸入數(shù)字包含小數(shù),不限制長度 export function getFloorNumNoLength(val) { const t = val.charAt(0) if (t === '.') { return val.replace('.', '') } val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.') // 先把非數(shù)字的都替換掉,除了數(shù)字 val = val.replace(/[^\d.]/g, '') return val }
到了這里,關(guān)于vue輸入框只能輸入數(shù)字類型,禁止輸入和粘貼e的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!