Comments (18)
using bcmath?
from money.
using gmp?
from money.
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
from money.
see https://github.com/mathiasverraes/money/pull/55/files#r16972250
from money.
Which BigDecimal class are you planning to use?
I am working on an implementation using https://github.com/Litipk/php-bignumbers
from money.
@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:
https://github.com/josecelano/money/blob/master/lib/Money/BigMoney.php
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.
from money.
@josecelano big integer values are supported now on the nextrelease branch.
from money.
OK thanks @sagikazarmark but I do not see any big integer in that brancg. It seems internal amount attribute is still an integer.
from money.
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.
from money.
@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 add
method returns a string (gmp_strval
) but Money constructor expects an integer.
from money.
@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.
from money.
@josecelano This is fixed in #133.
from money.
What is the status of this issue?
from money.
@TNAJanssen To be implemented after 3.0 will be released.
from money.
@TNAJanssen The initial PR has been proposed.
from money.
@TNAJanssen Maybe you could give some feedback.
from money.
π 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".
from money.
@bmeynell If it is critical you might as well help to get it done, e.g. give your feedback on PR #335. It is all too easy to say something is critical and do nothing at all. Nonetheless, your comment helped me awaking the PR, see my comment from today in the thread.
from money.
Related Issues (20)
- `roundToUnit` does not handles amounts less than 1 unit HOT 3
- SwapExchange does not work with small floating point numbers HOT 1
- PHPUnit comparator breaks under PHPUnit 10/comparator 5 HOT 1
- Aggregate Currencies unexpected behaviour HOT 1
- Bring back HRK currency HOT 3
- numberFormat refuses to use comma as decimal separator. HOT 2
- Possibility to allocate with custom rounding parameter
- Leading zeros. Confusing amount after parsing and formatting HOT 1
- Cryptocurrency Advice HOT 2
- Documentation is out of date HOT 1
- Question about Yemenis YER cent amount HOT 1
- Multiply when float will going wrong result HOT 6
- Incorrect βminorUnitβ Value for Iranian Rial (IRR) HOT 1
- "psr/cache" 3 can not be installed because of cache/tag-interop HOT 2
- Documentation needs details on tax calculation HOT 3
- ISK convert gives wrong amount (x100) HOT 1
- This field is attempting to submit the form on page load for some reason HOT 1
- . HOT 1
- Official website is not working HOT 1
- Enhancement:: Allow multiply by float numbers less than 1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from money.