Skip to content

fix(label): axisLabel precision causes floating-point error in number formatting (toFixed) #21037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

im0505
Copy link

@im0505 im0505 commented Jun 16, 2025

Brief Information

This pull request is in the type of:

  • bug fixing
  • new feature
  • others

What does this PR do?

Removing 2 additional digit when to use toFixed for precision

echarts/src/scale/helper.ts

Lines 101 to 104 in f4c244c

export function getIntervalPrecision(interval: number): number {
// Tow more digital for tick.
return getPrecision(interval) + 2;
}

Try demo

option = {
  grid: {
    left: 300,
  },
  xAxis: {
    type: 'category',
    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri']
  },
  yAxis: {
    type: 'value',
    interval: 0.0670572916666667,
    max:  0.1341145833333334,
    min: -0.2011718750000001,
    splitNumber: 5
  },
  series: [
    {
      data: [
        0.060546845,
        0.0928, 
        0.00097656, 
        0.02389, 
        0.006238
        ],
      type: 'bar'
    }
  ]
};

Fixed issues

#21036

Details

Before: What was the problem?

image
toFixed can have residual floating-point noise.
#5986 seems to be covered for now.

After: How does it behave after the fixing?

image

Document Info

One of the following should be checked.

  • This PR doesn't relate to document changes
  • The document should be updated later
  • The document changes have been made in apache/echarts-doc#xxx

Misc

ZRender Changes

  • This PR depends on ZRender changes (ecomfe/zrender#xxx).

Related test cases or examples to use the new APIs

N.A.

Others

Merging options

  • Please squash the commits into a single one when merging.

Other information

@im0505 im0505 changed the title fix(label): axisLabel precision causes floating-point error in number… fix(label): axisLabel precision causes floating-point error in number formatting (toFixed) Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant