Skip to content

[Bug] 聚合功能出现js浮点数精度问题 #5102

@BubbleLeaf

Description

@BubbleLeaf

Version

1.25.0

Link to Minimal Reproduction

https://visactor.com/vtable/demo/list-table-data-analysis/list-table-aggregation-multiple

Steps to Reproduce

将下面的代码复制到代码框中就能看到了

const input_editor = new VTable_editors.InputEditor({});
VTable.register.editor('input', input_editor);
var tableInstance;

const records = [
  {
    num:0.1
  },
  {
    num:0.2
  },
];
const columns = [
  {
    field: 'num',
    title: '数值',
    width: 80,
    aggregation: {
      aggregationType: VTable.TYPES.AggregationType.SUM,
      formatFun(value) {
        return '汇总:'+value;
      }
    }
  }
];
const option = {
  container: document.getElementById(CONTAINER_ID),
  records,
  // dataConfig: {
  //   filterRules: [
  //     {
  //       filterFunc: (record: Record<string, any>) => {
  //         return record.id % 2 === 0;
  //       }
  //     }
  //   ]
  // },
  columns,
  tooltip: {
    isShowOverflowTextTooltip: true
  },
  frozenColCount: 1,
  bottomFrozenRowCount: 2,
  rightFrozenColCount: 1,
  overscrollBehavior: 'none',
  autoWrapText: true,
  widthMode: 'autoWidth',
  heightMode: 'autoHeight',
  dragOrder: {
    dragHeaderMode: 'all'
  },
  keyboardOptions: {
    pasteValueToCell: true
  },
  eventOptions: {
    preventDefaultContextMenu: false
  },
  pagination: {
    perPageCount: 100,
    currentPage: 0
  },
  theme: VTable.themes.DEFAULT.extends({
    bottomFrozenStyle: {
      bgColor: '#ECF1F5',
      borderLineWidth: [6, 0, 1, 0],
      borderColor: ['gray']
    }
  }),
  editor: 'input',
  headerEditor: 'input',
  aggregation(args) {
    if (args.col === 1) {
      return [
        {
          aggregationType: VTable.TYPES.AggregationType.MAX,
          formatFun(value) {
            return '最大ID:' + Math.round(value) + '号';
          }
        },
        {
          aggregationType: VTable.TYPES.AggregationType.MIN,
          showOnTop: false,
          formatFun(value, col, row, table) {
            return '最小ID:' + Math.round(value) + '号';
          }
        }
      ];
    }
    if (args.field === 'salary') {
      return [
        {
          aggregationType: VTable.TYPES.AggregationType.MIN,
          formatFun(value) {
            return '最低低低薪资:' + Math.round(value) + '元';
          }
        },
        {
          aggregationType: VTable.TYPES.AggregationType.AVG,
          showOnTop: false,
          formatFun(value, col, row, table) {
            return '平均平均平均:' + Math.round(value) + '元 (共计' + table.recordsCount + '条数据)';
          }
        }
      ];
    }
    return null;
  }
  // transpose: true
  // widthMode: 'adaptive'
};
tableInstance = new VTable.ListTable(option);
// tableInstance.updateFilterRules([
//   {
//     filterKey: 'sex',
//     filteredValues: ['boy']
//   }
// ]);
window.tableInstance = tableInstance;
tableInstance.on('change_cell_value', arg => {
  console.log(arg);
});

Current Behavior

Image

Expected Behavior

修复一下吧

Environment

- OS:
- Browser:
- Framework:

Any additional comments?

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions