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
fix: inaccurate floating-point calculations #1369
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
By the way, the way the native |
Why do we need to use a library to handle this? We already have a library for number handling, im not sure I see any benefit in using two, also can you resolve the conflicts please so we can at least run the CI 👍🏼 |
I wasn't aware that Strapi has a number handling library for mitigating floating-point issues. |
I didn't say this exactly, I was proposing that the library in the DS currently (look at the NumberInput) component might be able to handle what you're trying to solve. |
Oh, I see. I believe it's a small bug that only affects the component (NumberInput) when using the arrowUp/arrowDown functionality with a step value of 0.01. You can find more details about this problem in the linked issue here: Issue Link. I've attempted to address this issue without relying on any external libraries, but I'm encountering a persistent floating-point problem. Additionally, I'm uncertain if using something like ".toFixed(2)" would provide a definitive solution, especially in scenarios where users input numbers with more than two decimal places. I'd appreciate your thoughts on this matter. Please let me know what you think. |
What does it do?
I used the big.js library to overcome the floating-point error that occurs in the NumberInput component when using the increment and decrement functions. The new implementation ensures that arithmetic operations are accurately performed, especially when dealing with decimal numbers.
Why is it needed?
These changes address the issues raised in Strapi/Strapi repo issue#18138.
In the main project, when trying to fill the restaurant fields, a bug occurs when selecting an averagePrice of 0.06 using the arrow controls in the restaurant fields. The arrows provide inaccurate precision, resulting in 0.0600000001 instead of 0.06 when reaching this value. This issue also randomly affects other values.
See the issue Strapi/Strapi repo issue#18138 for better understanding
The issue demonstration:-
How to test it?
I haven't completed the test yet due to the discovery of some missing testing packages, which can be seen as another issue. As a result, I've chosen to divide the task into two separate steps.
Related issue(s)/PR(s)
The related issue is mentioned in the main repo of strapi: strapi/strapi#18138