-
Notifications
You must be signed in to change notification settings - Fork 439
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
Fractions of a cent #40
Comments
The core of multiply uses: (int) round($this->amount * $multiplier, 0, $rounding_mode) It works as follows:
So the answer is yes, it can do what you are asking, in the sense that you can have a float multiplier, but remember that the Money class works in the smallest currency unit, so in the case of USD as an example, you can't get sub-cents values. 1 cent is the smallest unit, and the multiply method will respect that and your rounding mode to arrive at the new value for your new Money value object. |
If you need high precision, you could build a BigMoney class. See
|
Thanks @mathiasverraes based on googling for joda-money I found this class: https://github.com/ikr/money-math-php |
announcing Keios/MoneyRight - bcmath based money object heavily based on your work @mathiasverraes, we were using your library, so MoneyRight has API matching 1.2.1 release and can work as drop-in replacement for projects depending on GAAP 4 decimal points precision. |
This is also a problem when you use allocate with floats and you have results that have fractions of cents. Those then are cut off and will lead to errors. I don't think this is technically a bug, but I was not aware of this.
|
Let's make this happen too. Why not create a new class I think we can reuse the calculators are created in PR #115, but rounding should be extended with precision. Only @sagikazarmark Do you have any specific ideas on this topic? |
The rounding should be performed upon instantiation or formatting of the |
This is a duplicate of #7. |
Does this work for fractions of a cent? How accurate is it if I use the multiply and pass in something like 0.1234?
The text was updated successfully, but these errors were encountered: