Skip to content

Conversation

ericsoderberghp
Copy link
Contributor

What does this PR do?

Adds some truncation to deal with floating point precision issues in javascript.

From the test case shown below, 2.26 + 8.04 === 10.299999999999999 instead of 10.3.

See this post for some details on the underlying shortcomings of javascript: https://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript

Where should the reviewer start?

Meter.js

What testing has been done on this PR?

The test scenario from the issue involves:

<Meter
  type="circle"
  values={[{ value: 2.26 }, { value: 8.04 }]}
  max={10.3}
/>

A unit test has been added.

How should this be manually tested?

see ^^^

Do Jest tests follow these best practices?

follows existing test patterns

What are the relevant issues?

#6190

Do the grommet docs need to be updated?

no

Should this PR be mentioned in the release notes?

yes

Is this change backwards compatible or is it a breaking change?

backwards compatible

@ericsoderberghp ericsoderberghp merged commit 9de09e4 into master Jun 17, 2022
@ericsoderberghp ericsoderberghp deleted the fix/meter-floatprecision branch June 17, 2022 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Circle Meter chart not rendering properly for specific input values
2 participants