Git Product home page Git Product logo

Comments (18)

mathiasverraes avatar mathiasverraes commented on June 30, 2024

using bcmath?

from money.

sa-tasche avatar sa-tasche commented on June 30, 2024

using gmp?

from money.

camspiers avatar camspiers commented on June 30, 2024

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.

mathiasverraes avatar mathiasverraes commented on June 30, 2024

see https://github.com/mathiasverraes/money/pull/55/files#r16972250

from money.

josecelano avatar josecelano commented on June 30, 2024

Which BigDecimal class are you planning to use?
I am working on an implementation using https://github.com/Litipk/php-bignumbers

from money.

josecelano avatar josecelano commented on June 30, 2024

@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.

sagikazarmark avatar sagikazarmark commented on June 30, 2024

@josecelano big integer values are supported now on the nextrelease branch.

from money.

josecelano avatar josecelano commented on June 30, 2024

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.

sagikazarmark avatar sagikazarmark commented on June 30, 2024

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.

josecelano avatar josecelano commented on June 30, 2024

@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.

sagikazarmark avatar sagikazarmark commented on June 30, 2024

@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.

frederikbosch avatar frederikbosch commented on June 30, 2024

@josecelano This is fixed in #133.

from money.

TNAJanssen avatar TNAJanssen commented on June 30, 2024

What is the status of this issue?

from money.

frederikbosch avatar frederikbosch commented on June 30, 2024

@TNAJanssen To be implemented after 3.0 will be released.

from money.

frederikbosch avatar frederikbosch commented on June 30, 2024

@TNAJanssen The initial PR has been proposed.

from money.

frederikbosch avatar frederikbosch commented on June 30, 2024

@TNAJanssen Maybe you could give some feedback.

from money.

bmeynell avatar bmeynell commented on June 30, 2024

πŸ‘ 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.

frederikbosch avatar frederikbosch commented on June 30, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.