Skip to content

sum方法求和精度在某些情况下失真 #68

@zkzgs

Description

@zkzgs

可复现的链接:

https://codesandbox.io/p/sandbox/5qhxzr?file=%2Fsrc%2Fviews%2FDemo1.vue%3A27%2C1

问题描述与截图:

得出结果精度不一致,与实际精度有偏差,放在数组前面和中间和放在最后计算出的结果也不相同
const a = [ 30, 3, 0.0175, 18, 0.0145, 0.38, 13, 15600, 0.7, 14, 1.57, 1, 30, 760, 0.15, 45, 1.6, 1, 1011.468, 13, 3, 1, 1.76, 0.018, 13, 15600, 3, 3, 80, 15600, 2.3, 14.6, 485, 0.2749008, 760, 2.3, 760, 13, 123, 109.073, 760, 0.68, 0.68, 1900, 14, 22.5, 1900, 1900, 15600, 2.05, 550, 1.23, 485, 13, 2.3, 0.2, 1900, 220, 760, 20, 13, 1900, 485, 2050, 30, 0.65, 1, 500, 1.68, 30, 0.015, 3, 14, 1, 3, 1.69, 13, 13, 1.68, 14.5, 1.75, 485, ]; const b = 0.26710027;
image

期望的结果:

计算结果与最高小数位保持一致

操作系统:

window 10

浏览器版本:

Chrome 130.0.6723.117

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfixhas been fix

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions