import Decimal from './../decimal' // 解决精度问题 (vue页面引入)
decimal.js
export default {
round: (value, exp) => {
return decimalAdjust('round', value, exp);
},
floor: (value, exp) => {
return decimalAdjust('floor', value, exp);
},
ceil: (value, exp) => {
return decimalAdjust('ceil', value, exp);
}
};
function decimalAdjust(type, value, exp) {
// If the exp is undefined or zero...
if (typeof exp === 'undefined' || +exp === 0) {
return Math[type](value);
}
value = +value;
exp = +exp;
// If the value is not a number or the exp is not an integer...
if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) {
return NaN;
}
// Shift
value = value.toString().split('e');
value = Math[type](+(value[0] + 'e' + (value[1] ? +value[1] - exp : -exp)));
// Shift back
value = value.toString().split('e');
value = +(value[0] + 'e' + (value[1] ? +value[1] + exp : exp));
return value;
}
数据过滤:
// 过滤相同月份数据
gl () {
var arr = []// 用来存放合并列数
var data = [{
ny: '202001',
},
{
ny: '202001',
},
{
ny: '202002',
}]
data.sort(this.compare('ny'))// 注意,一定要排序,不排序,会重复判断,从而错误
for (var i = 0; i < data.length;) { // 按照属性判断属性合并列数
var count = 0
for (var j = i; j < data.lenth; j++) {
if (data[i].ny === data[j].ny) {
count++
}
}
arr.push({
plName: data[i],
count: count
})
i += count
}
for (var k = 0; k < arr.length; k++) {
console.log(arr[k])
}
},
// 按月份排序
compare (property) {
return function (a, b) {
var value1 = Number(a[property])
var value2 = Number(b[property])
return value1 - value2
}
},