-
Notifications
You must be signed in to change notification settings - Fork 441
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
Deal with decimals using PreciseMoney #7
Comments
using bcmath? |
using gmp? |
Related to this, there is a fairly big issue with integer overflow in this library. Although I really like your library Mathias, I choose to use https://github.com/sebastianbergmann/money for various reasons, but I still want to help this library. If you have a look at my recent pull requests:
This library suffers from the same issues, either silently (and wildly) losing imprecision, or actually failing but not really given appropriate errors. Regards |
Which BigDecimal class are you planning to use? |
@mathiasverraes I have done a test implementing Money class using a BigDecimal library (https://github.com/Litipk/php-bignumbers) I have only changed amount type from integer to Decimal. Here is the test: I call it BigMoney but I only want to use your libary with big integers (I do not need to scale over the currency default decimal places). Then I suppose it is a new implementation of Money. Althougth I think it could be easily changed to implement your BigMoney. Just after the commit I have found this new library: https://github.com/keiosweb I suppose I can use it for all possible values (int, big int and more presicion). Do you think it's better to have only one class rather than 2 as you propose? I think it is a good idea to have two but the first one (Money) should support big amounts. I suppose there could be countries with hyperinflation where you can easily overflow max integer in 32 bits systems. |
@josecelano big integer values are supported now on the nextrelease branch. |
OK thanks @sagikazarmark but I do not see any big integer in that brancg. It seems internal amount attribute is still an integer. |
Integer support is implemented as Calculators. If you have gmp or bcmath installed, it will automatically use those which allows you to represent big integers. |
@sagikazarmark I have not had time to test this new verion but there is something I still do not understand, you are using big integer functions for calculations but you are still using an integer to store the amount attribute, then you still have the integer max size limit. For example if I want to add two Money objects and the result is greater than max integer value (in 32 or 64 bit systems), then the result does not fit in an integer. GMP calculator |
@josecelano that's what the docblock says, but look at the validation: https://github.com/mathiasverraes/money/blob/nextrelease/src/Money.php#L57 There is a PR which fixes that docblock as well. |
@josecelano This is fixed in #133. |
What is the status of this issue? |
@TNAJanssen To be implemented after 3.0 will be released. |
@TNAJanssen The initial PR has been proposed. |
@TNAJanssen Maybe you could give some feedback. |
👍 Agree this is a critical feature and a must-have when requiring handling of fractions of lowest denominations (e.g., "fraction of cents"). Comes up a lot in computing averages, applying discounts, and even simple addition of multiple amounts that are in "fractions of cents". |
idea from http://joda-money.sourceforge.net/userguide.html
The text was updated successfully, but these errors were encountered: