Commit 4bd10ec2 authored by 潘永坪's avatar 潘永坪

公共方法增加

parent 745d7900
......@@ -16,4 +16,26 @@ const app = new Vue({
...App
})
app.$mount()
//保留小数方法,第一个参数是需要保留的数字,第二个参数是需要保留几位小数
function toFixed(number, m) {
if (typeof number !== 'number') {
throw new Error("number不是数字");
}
let result = Math.round(Math.pow(10, m) * number) / Math.pow(10, m);
result = String(result);
if (result.indexOf(".") == -1) {
if(m != 0){
result += ".";
result += new Array(m + 1).join('0');
}
} else {
let arr = result.split('.');
if (arr[1].length < m) {
arr[1] += new Array(m - arr[1].length + 1).join('0')
}
result = arr.join('.')
}
return parseFloat(result)
}
Vue.prototype.$toFixed=toFixed
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment