Closed rtheunissen closed 3 years ago
@rtheunissen Nice work over there with the extension, I like it. I was not aware of it.
@sagikazarmark I am in favour of merging this PR in the 3.x range. And I also think @rtheunissen is right regarding risks of float usage. We should take care of that in the 4.x releases.
Sorry for the late answer, time has passed quickly. I'm definitely in favor of moving to PHP 7.3+ and improving internal semantics.
One comment related to this particular PR: we have moved to GitHub Actions recently, so the CI part of the PR needs to be actualized. Other than that 👍
Can you update the PR @rtheunissen ?
and to not require that the return result of the calculators be string.
What should the result be then?
and to not require that the return result of the calculators be string.
What should the result be then?
An abstract number type. The decimal extension does not use strings internally, so to convert to and from string for every operation is wasteful. Instead, we can create an interface like Number
that supports whatever operations we need, and leave it up to the implementation to store the internal data however it wants. BC and any other string-based calculator could use a generic StringNumber
, for example.
Would this be an interface between Money
and calculators? Or an internal representation that Money
uses as well? (Currently `Money uses string internally)
Since we want to keep maintenance for this library not too high, I would recommend publishing this in a separate repo. I am very sorry for the delay.
Hi everyone, this patch adds support for the new php decimal extension.
It's a real shame how the calculators are set up, because it allows
float
to used (thereby opening the door to poor precision) and requires that the return value of each operation bestring
. The decimal extension uses an optimized internal value that is not a string, so the conversion to and from string for every operation adds unnecessary overhead.What I'd love to see is a PHP 7 update of this library where input is normalized (
string
orint
, ideally) before being passed to the calculator, and to not require that the return result of the calculators be string.This implementation passes the tests though, so it'll have to do for the time being.
Please see http://php-decimal.io for more information.