Skip to content
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

Using the bcmath library instead of directly calculating on floating values #45

Open
zxy19 opened this issue Jul 27, 2024 · 2 comments
Open

Comments

@zxy19
Copy link

zxy19 commented Jul 27, 2024

I noticed that the extension is using float type to calculate money. Float operations should be avoided in money calculation as it leads to unavoidable inaccuracy (such as 0.3000001). Could you use the bcmath library for high-precision calculations and change the type to currency or decimal in database?

@AntoineFr
Copy link
Owner

Hello @zxy19 , thank you for your suggestion.

For the decimal database type, I thought about it earlier but the problem is that you have to specify the number of decimals you want to keep, and this can vary a lot between 2 extension users.
For the bcmath functions, they need a PHP module to be installed so it may not be portable, however I'll take a look at it.

To solve this problem, I also thought of storing the money as an integer in database, and add a display settings for this extension to divide the money visually in the frontend.
For example, it would be stored in database as 1234567 with a division settings of 100 and it would display as 12345.67 in the forum.

@zxy19
Copy link
Author

zxy19 commented Sep 5, 2024

Yes I think it's a good idea to use integer so that it would be more compatible with the large amount of extension which depends on this extension. Website administrator can easily make the old extension works by multiply the original money amount by 100 even the extension has not update.

I wonder if it will be accomplish in furture version?

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

No branches or pull requests

2 participants