antvis / antvis/data-set

使用transform aggregate的 sum 累加时候,小数点存在精度丢失问题

Open
#94 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
251
Forks
49
PR merge metrics
No merged PRs in 30d

Description

`
const dv = new DataSet().createView().source([
{
item: '2019',
columnValue: 1.01,
type: 'a'
},
{
item: '2019',
columnValue: 2.01,
type: 'a'
},
{
item: '2020',
columnValue: 1.01,
type: 'a'
},
{
item: '2020',
columnValue: 2.22,
type: 'a'
},
])
dv.transform({
type: 'aggregate', // 别名summary
fields: ['columnValue'], // 统计字段集
operations: ['sum'], // 统计操作集
as: ['value'], // 存储字段集
groupBy: ['item', 'type'], // 分组字段集
})

console.log('dv', dv.rows)
`
#### 输出结果
![image](https://user-images.githubusercontent.com/10897871/92208146-3134e080-eebd-11ea-9185-bbdfd8d94ea5.png)

#### 原因
sum 使用的第三方库 simple-statistics 里面并没有处理浮点计算精度丢失问题
![image](https://user-images.githubusercontent.com/10897871/92208335-8a9d0f80-eebd-11ea-94fd-3b55a468a61d.png)
![image](https://user-images.githubusercontent.com/10897871/92208368-9a1c5880-eebd-11ea-9351-14dc3bfde0b5.png)

希望能修复这个问题,感谢

Contributor guide

Open the contributing guide

Research direction

Start at the aggregate transform using the provided DataSet example, then inspect how its sum operation delegates to the mentioned simple-statistics dependency. Reproduce the grouped decimal calculation and verify that the resulting values no longer show floating-point precision loss.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.